File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Please help Newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Please help Newbie" Watch "Please help Newbie" New topic
Author

Please help Newbie

D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

Sorry for silly questions, but my manager wants me to use EJB, ok, I'm fine. I bought 3 EJB books and read them for 3 months, and still has no clue, so please help me if you can:
1. I have a thread which can send message obviously using JMS and call other session beans. How can I start this thread under app server, let's say jBoss? (Generally I do not have servlets, JSP and other things).
2. I want to spawn more threads for some other processing, my manager told me, use thread pool giving by app server, how can I request a thread from a pool to do my task?
3. I create some objects, I know that entity beans are stored in a pool, can I store arbitrary objects in the pool and reuse them time after time, what's API for that prepared by app server.
4. When I use clustering and my thread is running on one cluster, how can I prevent it running on another one, and when current cluster is going down, then my thread should start on another cluster, how can I guarantee that?
Please answer if you know exact answer, I am not interested in advice around.


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
1. I have a thread which can send message obviously using JMS and call other session beans. How can I start this thread under app server, let's say jBoss? (Generally I do not have servlets, JSP and other things).
There is no standard way of starting your own threads in J2EE applications. JBoss might, however, provide a proprietary way of doing this. You can also use a simple servlet that is configured with load-on-startup in web.xml, which causes the application server to load and initialize that class during webapp startup, effectively providing you a place where you can start a thread and be sure that the code won't be executed again. The same can be accomplished by using a ServletContextListener, which gets notified when the web application starts up or is destroyed.
2. I want to spawn more threads for some other processing, my manager told me, use thread pool giving by app server, how can I request a thread from a pool to do my task?
Again, any thread pools made available by the application server are a proprietary feature. Refer to vendor documentation.
3. I create some objects, I know that entity beans are stored in a pool, can I store arbitrary objects in the pool and reuse them time after time, what's API for that prepared by app server.

No, you can't store arbitrary objects int the entity bean pool. However, you can use your own object pool, using Jakarta Commons Pool for example.
4. When I use clustering and my thread is running on one cluster, how can I prevent it running on another one, and when current cluster is going down, then my thread should start on another cluster, how can I guarantee that?
Again, there is no standard way of doing this. One possible way of doing this would be to use a JMS topic for "announcing" who's the "master thread" right now. Each cluster node would have a thread running, but only the one who has obtained some kind of virtual token would actually execute it's tasks -- the rest would just go back to sleep after checking that the master is still alive. If you decide to research this alternative further, I'd suggest keeping in mind that JMS doesn't guarantee the order of message delivery.
Please answer if you know exact answer, I am not interested in advice around.
Is it really in your interest to say things like this?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

Thank you, you post is quite helpful. I also thought about using a dummy servlet to start my own processing.
Regarding my one master thread requirement, you gave me a good idea, I'll also look in JavaGroups, where multiple threads can act as one.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Great. Let us know what you came up with, ok?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please help Newbie