This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 65
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: 65
Please anyone reply
Sindhu Kodoor
Ranch Hand

Joined: Sep 03, 2010
Posts: 65
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: 65
Thanks a lot ramprasad it works now !!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to schedule a subscriber program to continuously run for a specified duration
 
Similar Threads
Phone subscribers multiple threads: incompatible type errors and cannot find symbols error
durable Vs non-durable Topic subscription
Persisting messages in JMS
Can a class outsiad the ../WEB-INF/ call the class under ../WEB-INF/?
Two simpe methods calling each other not working as expected