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 How to schedule a subscriber program to continuously run for a specified duration 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 "How to schedule a subscriber program to continuously run for a specified duration" Watch "How to schedule a subscriber program to continuously run for a specified duration" New topic
Author

How to schedule a subscriber program to continuously run for a specified duration

Sindhu Kodoor
Ranch Hand

Joined: Sep 03, 2010
Posts: 66
Hi,

There is a requirement to schedule the subscriber stand alone program to keep running for duration of system date + 6 days , when it is system date + 6days it should stop running or if there is a stop file ( any file named as stop file) within a specified directory, then also it should stop running.

Please can you suggest me ways of continuously keep the subscriber program running ( esp the onMessage() method ), even though there are messages published for that topic or not , it should keep running and once a message is published then it should retrieve the message.

Kindly help!

Sindhu Kodoor
Ranch Hand

Joined: Sep 03, 2010
Posts: 66
Please anyone reply
Sindhu Kodoor
Ranch Hand

Joined: Sep 03, 2010
Posts: 66
Since the subscriber is a standalone program i.e, with the main method , is it ok to use the current Thread.sleep(Long l) or Thread.wait() ?
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Please can you suggest me ways of continuously keep the subscriber program running ( esp the onMessage() method ), even though there are messages published for that topic or not , it should keep running and once a message is published then it should retrieve the message.


The start() method of the Connection object is a bootstrap facility that precisely does that. There is no need to do anything more.
Create a connection from the connection factory, a session from the connection and a subscriber from the session. Calling start() on the connection ensures that the messages start flowing into the subscriber until stop() is called.

Going back to your original question of scheduling a subscriber for a specific period of time, you would have to have a seperate thread that polls the directory for your stop file or else checks for elapsed time. This thread would have a handle to the connection object and would call stop() and close() on the connection object whenever a condition evaluates to true.

cheers,
ram.

Sindhu Kodoor
Ranch Hand

Joined: Sep 03, 2010
Posts: 66
Thanks a lot ramprasad it works now !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to schedule a subscriber program to continuously run for a specified duration