• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can not find the pattern to use!!!

 
Dany Robbins
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to design a J2EE application which is quite different from what I have done to this day, and I can't find how to design it.
I have (for now) 2 points to where the data will be arriving. One is a database table, I will take this as my exemple. I can NOT write store procs or touch the database, I can poll it however. But how can I have objects which are constantly running in a J2EE container? I can't create threads in an EJB, EJB won't "run" by themself(need a call on them from a client), etc etc. How do you run "normal" objects inside an application server? Is it even possible?
I really strived to RTFM on this one, but I have not find much on this topic!
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most Application Servers provide a mechanism to launch classes upon server startup. Within these plain Java classes you can create threads and generally do whatever you need to do.
In the future these types of problems should become easier to deal with since EJB 2.1 is providing a timer mechanism for EJB. It would be trival at that point to write an EJB that fires every minute or so to poll a database table.
[ January 14, 2003: Message edited by: Chris Mathews ]
 
Dany Robbins
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for your quick response!
I just tought about something...
I could, instead of having a startup class, wait for a user request to start the process(thru a servlet).
This could call a method on a Stateless session bean which would itself poll the database inside a loop, sending message to a MDB when new data is inserted in the database. It would exit the loop when the user send a stop request to the application.
Do this seem logic? Do you see any problem with this aproach?
Thanks!
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dany Robbins:
Hi, thanks for your quick response!
I just tought about something...
I could, instead of having a startup class, wait for a user request to start the process(thru a servlet).
This could call a method on a Stateless session bean which would itself poll the database inside a loop, sending message to a MDB when new data is inserted in the database. It would exit the loop when the user send a stop request to the application.
Do this seem logic? Do you see any problem with this aproach?
Thanks!

This would not work, since the call to your Session Bean is not asynchronous. This would also needlessly hammer the CPU.
You need some type of threaded process that is going to fire periodically.
You could accomplish your goal by using a JMX Timer that fires at specific intervals. The Timer could then call a Session Bean to poll the db. However, the Timer will still need to be started using a Startup Class. This is under the assumption that your Application Server supports JMX.
 
Dany Robbins
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right, did not tough about that.
Maybe my servlet should send a message to an MDB instead, those are asynchronous and I would not loop endlessly without stopping. I would probably use DBMS_ALERTs (oracle) and block until new messages are arriving.
[ January 14, 2003: Message edited by: Dany Robbins ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!