We help IT Professionals succeed at work.

Application Server in Thread

jagbir_paul
jagbir_paul asked
on
Is it advisable to do multi threading in Application Server? One of my frnd told me that while doing application server programming it is not good to do thread programming as user thread may interfer with threads of App Server.... is this true?
Comment
Watch Question

Top Expert 2016

Commented:
It is true. It's an anti-pattern in J2EE
Mick BarryJava Developer
Top Expert 2010

Commented:
not really true, no special issues with threading on an app server.
Mick BarryJava Developer
Top Expert 2010

Commented:
in fact (threaded) products like quartz are regularly used in app server to manage background processing and threads.
Java Developer
Top Expert 2010
Commented:
>  it is not good to do thread programming as user thread may interfer with threads of App Server.... is this true?

thats definitely wrong, threads in an app server are no different to threads on any java application.
Top Expert 2016
Commented:
There are better ways to manage user-created thread, some of the app-server specific, others not. See

http://www.theserverside.com/discussions/thread.tss?thread_id=44353
Top Expert 2016

Commented:
In your case, you probably want

http://www.ibm.com/developerworks/library/specification/j-commonj-sdowmt/index.html

since

"The Work Manager for Application Servers specification provides an application-server-supported alternative to using lower-level threading APIs, which are inappropriate for use in managed environments, as well as being too difficult to use for most applications."

Author

Commented:
So should one use Thread Programming in this case... if this is not good practice what can be adverse effects?
Mick BarryJava Developer
Top Expert 2010

Commented:
> http://www.ibm.com/developerworks/library/specification/j-commonj-sdowmt/index.html

And how exactly is that (very outdated) document relevant?
Mick BarryJava Developer
Top Expert 2010

Commented:
> So should one use Thread Programming in this case... if this is not good practice what can be adverse effects?

its not bad practice, threading is used in app server all the time.
Follow the same practices you follow when threading a java application.
Top Expert 2016

Commented:
>>what can be adverse effects?


Read the link i posted at http:#32991884
I would back objects, in olden days it was said that apps running on a container( appserver ) should not create threads because the appserver manage the threads. that holds good as long as the requests coming through the appserver but there are times the apps itself had to generate request and execute them in separate thread. one classic example as given by objects is the scheduler quartz which has its own threadpool...

you can always use threads  as long as it doesn't make the appserver starve for threads...
Top Expert 2016

Commented:
>>it was said that apps running on a container( appserver ) should not create threads because the appserver manage the threads

That's right, and that's still the case.

The point is, there are ways of mitigating the risks, so they should be used, not ignored
Mick BarryJava Developer
Top Expert 2010

Commented:
> That's right, and that's still the case.

sorry but its not.
OC4J has an option -userThreads, according to me it means that the developers are encouraged to use their own threads in the applications :-)
In my poor opinion using user threads in applicaions running on a container is not bad practice, but when you use threads in such as applications it's more risky because you have to have in mind one more thing - the threads managed by the container.

Top Expert 2016

Commented:
>>but when you use threads in such as applications it's more risky because you have to have in mind one more thing - the threads managed by the container.

Yes, that's my point. You mitigate that by using the practices i mentioned earlier. Therefore not using those practices is (relatively) bad practice
Mick BarryJava Developer
Top Expert 2010

Commented:
> . Therefore not using those practices is (relatively) bad practice

everyone else appears to disagree with you
Top Expert 2010

Commented:
If your application REQUIRES an application server, it is likely to use EJBs. You are not supposed to create new threads in EJB methods.

If your application is not really an EJB application and is merely deployed to an application server, perhaps using some of the services it provides, you should be fine with multi-threading.

Commented:
hi  jagbir_paul

it's not a good practice to create your own thread inside a application server,
the issue is in that case the application will have no visibility of your home brewd thread.
put it simple this might have potential issue, and hard to troubleshoot if anything goes wrong

usually the application server will come alone with a verdor specific interface for customers to spaw new thread, for example, for example, websphere does. this kind of implementation is not good, although this time the applciation is able to see and manage the thread your code spaw, but this will make your code vendor dependent.
which means, if you are not going to use websphere as ur application server, you choose JBoss, then you have to change your code.

frankly speaking, there is not better balance point of this... persoanlly i prefer the first approach if you are VERY farmiliar with OS and THREAD.

cheers

Leaonow
Kevin CrossChief Technology Officer
Most Valuable Expert 2011

Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.