aspose file tools*
The moose likes Java in General and the fly likes How to pass the new incoming Data to another Class after Polling? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to pass the new incoming Data to another Class after Polling?" Watch "How to pass the new incoming Data to another Class after Polling?" New topic
Forums: Java in General Threads and Synchronization
Author

How to pass the new incoming Data to another Class after Polling?

Magesh babu Sourashtra sundareswaran
Greenhorn

Joined: Jan 09, 2013
Posts: 5
This class does Polling and checks for new incoming messages.Now how can i achieve both Polling and check for new data at the same time? At last all the data had to be fed back to the Polling


My task is to Poll the table from the database and also check for new incoming message.After polling first I get the new incoming data, Now my problem is

1.How to pass this new data into another class, to process the message.

2.And how to pass these new messages into another class.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Magesh babu Sourashtra sundareswaran wrote:This class does Polling and checks for new incoming messages...

Magesh,

1. Welcome to JavaRanch.
2. You didn't use the code tags button properly. I've corrected your post this time, but you should always use the 'Preview' button to view your post before sending. I'd also suggest you read the UseCodeTags page again.
3. Your solution seems awfully "busy" - although I have to admit I don't like polling in general. Is there not some way that the database could simply tell your app when it has received a message?

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Magesh babu Sourashtra sundareswaran
Greenhorn

Joined: Jan 09, 2013
Posts: 5
Thank you Winston Gutkowski, Now I am proceeded with Polling, all I want to do is ... how to pass this new messages into another class respectively...
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2404
    
  28

Why can't you just process the messages right in your run loop? Is there a specific reason why you are putting it in a list?

Seems to me that you already keep polling for new messages, so I'm not following your second question. Are you asking how to put a message into the database?
Magesh babu Sourashtra sundareswaran
Greenhorn

Joined: Jan 09, 2013
Posts: 5
Jayesh A Lalwani wrote:Why can't you just process the messages right in your run loop? Is there a specific reason why you are putting it in a list?

Seems to me that you already keep polling for new messages, so I'm not following your second question. Are you asking how to put a message into the database?

No basically I have created three classes
1.Poller- does the Polling and Passes the new data from db to controller
2.Controller- this class has a thread Pool, which simultaneously calls the Poller and has the new data to be requested from processor
3.Processor- this class has to look for new data, process it and return it to controller.
So now my problem is how to implement the third phase...


The Following is my controller class
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Magesh babu Sourashtra sundareswaran wrote:No basically I have created three classes...

Sounds to me like you're ignoring good advice and have simply 'decided' on a solution (or possibly, you've been told how to do it) - which is rarely a good way to work.

However, that aside, "this class has to look for new data, process it and return it to controller" doesn't tell us a lot. You've presumably already written a class which interacts with your Controller, so I'm not quite sure what your problem is.

Winston
Magesh babu Sourashtra sundareswaran
Greenhorn

Joined: Jan 09, 2013
Posts: 5
Winston Gutkowski wrote:
Magesh babu Sourashtra sundareswaran wrote:No basically I have created three classes...

Sounds to me like you're ignoring good advice and have simply 'decided' on a solution (or possibly, you've been told how to do it) - which is rarely a good way to work.

However, that aside, "this class has to look for new data, process it and return it to controller" doesn't tell us a lot. You've presumably already written a class which interacts with your Controller, so I'm not quite sure what your problem is.

Winston

No Winston, not like ignoring your idea its a real help getting suggesstions from experts, since am new I couldn't predict my OO ways of programming , i was just posing my tasks which was given to me... ya as you said I have a class that interacts ,but what I have to do is "there should be a call from another class to this thread pool in controller such that it checks for new messages to process it" . They are expecting me to do asynchronous processing from my side. thank you...


Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2404
    
  28

Ahh so you want to process the messages using a thread pool? That's a good reason to put the message into a queue. Also, this means that this thread should be in Threads forum. I'll move it soon

ExecutorService already has a built in queue. You don;t need to reinvent the wheel and implement your queue. Also, what you want to do is execute the Processor in the ExecutorService, and your Poller should be running on a dedicated thread (or actually a good design would be that the thread should between executing Poller and Processor... but let's forget this for now.. its a little bit advanced)

Looks like you are calling the Poller from the ExecutorService, and you don't have a dedicated thread for the Poller. You might want to start off by looking at the javadoc for java.util.concurrent.ExecutorService. It has a most excellent example that is very very close to what you want to do here

Magesh babu Sourashtra sundareswaran
Greenhorn

Joined: Jan 09, 2013
Posts: 5
Jayesh A Lalwani wrote:Ahh so you want to process the messages using a thread pool? That's a good reason to put the message into a queue. Also, this means that this thread should be in Threads forum. I'll move it soon

ExecutorService already has a built in queue. You don;t need to reinvent the wheel and implement your queue. Also, what you want to do is execute the Processor in the ExecutorService, and your Poller should be running on a dedicated thread (or actually a good design would be that the thread should between executing Poller and Processor... but let's forget this for now.. its a little bit advanced)

Looks like you are calling the Poller from the ExecutorService, and you don't have a dedicated thread for the Poller. You might want to start off by looking at the javadoc for java.util.concurrent.ExecutorService. It has a most excellent example that is very very close to what you want to do here


Thanks for the info Jayesh, I will try executing this and come back you...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass the new incoming Data to another Class after Polling?