Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help Newbie

 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great. Let us know what you came up with, ok?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic