This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Which Design Pattern to Choose Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply Bookmark "Which Design Pattern to Choose" Watch "Which Design Pattern to Choose" New topic
Author

Which Design Pattern to Choose

Nabeel Shaheen
Greenhorn

Joined: Apr 22, 2010
Posts: 5
Hi All,

This is my first post, and your kindness is requested
[Edit:Ok its first in OO, Patterns section ]

I have a java application that runs in an eternal while loop. I want to pass messages to my application to e.g. gracefully shutdown, move to init state, current number of processed counts. Essentially I am looking for a pattern wherein there is a control thread that passes messages to business/Main thread and the Main thread asynchronously handles the message and updates the control thread. The control thread can have aribtrary IO mechanism.

There were two candidates that matched closed to my requirements
1. Observer Pattern
2. Task Pattern

From my understanding, observer pattern has (simplex) unidirectional information flow(although at oodesign, they advocate notify() can be implemented in push/pull mechanism with which i disagree), and I am more interested in a halfduplex/fullduplex.

Task Pattern looks promising candidate and can be used to monitor long running tasks (with appropriate interfaces) but I was not able to find detailed literature on the web for it.

I am here to seek some suggestions regarding the best pattern for implementing my problem.

Regards,
Nabeel


Vladimir Ozerov
Greenhorn

Joined: Sep 27, 2011
Posts: 14
I don't think that there is any pattern that will completely address your problem. At first you should clearly describe your requirements. Once it is done think of how to implement them and as far as I understand you need to think about threading issues first, but not about how to name the pattern.
Try to answer the following questions:
1) What is the complete set of operations you want to implement?
2) How should they interact with each other? (e.g. whether they can interfere or must be called sequentally?)
3) Should they be synchronous or asynchronous?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Which Design Pattern to Choose
 
Similar Threads
Question about MVC in Swing application
worker thread
Thread running behaviour
Monitor all sessions in server - my solution - your opinion
Observer-Pattern with EJB