开发者

how to use Thread inside Thread with ThreadSafty [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Is there a way where i can i use Thread inside Thread ? if so how to use that in Thread Safety Manner

I tried this Thread inside Thread where i got wrong result sometime. Please Help me how to figure out Thread inside Thread using Thread Safety

for(int i=0; i<numExpression; i++)
{
    final int _i = i;
    final SDISQuer开发者_JAVA百科yInfo _qryInfo = sdisQueryInfo;
    final SDISQueryComponent _qryComponent = qryCompoents;
    TCreate[i] = new Thread(new Runnable()
    {
        public void run()
        {
            _qryComponent.prepare(_qryInfo);
        }
    });
    TCreate[i].setName(_qryInfo.getQueryTerm(_i));
    TCreate[i].start();
}
for(Thread t : TCreate)
{
    t.join();
}

Here in this _qryCompoents.prepare(_sdisQueryInfo) is function which i am calling. This function has thread inside in it.


Sorry for this question i apology .. i couldn't able to remove this question.


In principle there is no issue with starting threads from other threads. There is no real difference between the threads (there aren't parent threads or child threads, so to speak).

I'm not sure what you mean by "this function has a Thread inside it...".

I'm assuming you mean that it will start another thread. By no means does that make a big difference, unless of course that inner thread is sharing information with other threads. You'd have to consult the documentation for SDISQueryComponent.prepare to find out whether that is the case.

My expectation is that SDISQueryComponent is ok with threading, for the simple reason that it is obviously designed with threading in mind (or it wouldn't start threads).

The most important thing I'd think of here, is that you might run into the point where creating more threads creates contention (due to context switching overhead and perhaps locking) making things slow.

In that case, the usual solution involves a thread pool and a worker queue. However, I don't know whether SDISQueryComponent supports using a thread pool, so that might be out of your hands

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜