• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using thread wait() in Java Resultset  RSS feed

 
Abhinandan Patil
Greenhorn
Posts: 8
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I'm trying to fetch some String data from data base table and pushing it in a JMS queue (Activemq). But in case of this push operation gets failed, Instead of processing next String data from the Resultset, I have wait (hance using wait() method from object class) and check for why the JMS push operation got failed. To incorporate this, I'm resending the same string again to JMS queue for which the push operation got failed - Using a TimerTask from util package. Below is Pseudo code I'm trying to explain here:



With this code, the wait code highlighted above is not making the main thread to wait for Timer thread to complete it's resenting task.

Somebody please help me out from to incorporate this situation.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why you would want to do such a peculiar thing. I wrote a lot of JMS code back when it was more popular and I would never have considered your idea as a potential solution for a queue failing to accept a message.

But about that code: you have a comment about a synchronized block but there is no synchronized block.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually... if you want to start a thread and then wait for it to finish, you call the thread's start method and then you call its join method. No messing with wait and notify necessary. But as soon as you do that it becomes obvious that you didn't need a thread at all.
 
Abhinandan Patil
Greenhorn
Posts: 8
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I'm new to JMS. My only objective here is, I don't want the messages which are fetched by resultset will be dropped before those will be pushed on the JMS queue, hence I'm trying to Push it back in a same queue by a timer thread until it get pushed successfully. Till this timer thread execution, main thread should not execute more resultset, hence I want to make it wait until timer thread completes its re-sending operations.

About the synchronized block you mentioned, my code posted here is just a pseudo code. Actually, I have executed wait() [in main thread] in a synchronized block to insure no other thread will execute this wait() operation, the same is with notify() in a Timer thread.

Do you think is this requirement can be achieved any other ways? Or this can be achieved using simple wait() and notify()? Because if I use join() on timer thread, it will continues to resend the message in a JMS queue only single time. While doing this, again if the message sending gets failed, timer thread will completes and main thread (executing the next message queue ) will start. This may lead to loss of failed message which i don't want here. I want the main thread strictly wait until the timer thread successfully send the message in a queue even after many attempts. So to wait the main thread, i'm planning to use wait while in timer thread after successfully completing message resend operation, I want to notify the main thread to pick the second message and this continues until the result set ends.

I adhere to this logic of message resending as I'm implementing one of the live component which shows real time status of some ATM's hence message loss will never be accepted in this environment. I believe this can be implemented using wait and notify calls.

Please assist me in this regard if you can!
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still haven't explained why you need a separate thread to do that retrying business. I don't see the point -- you want to wait until the retrying is complete anyway.

And I can tell you that if writing to a JMS queue fails, there is a serious problem and a simple retry isn't going to fix it. Besides, your comments mention a "framework" -- why doesn't the framework deal with fundamental things like this?
 
gyank kannur
Ranch Hand
Posts: 43
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This framework design seems a bit incorrect. Instead of pushing the failed messages to the queue, you could rather send all the failed messages to a temporary storage like a temp table. Once the main activity completes, you can process the failed ones.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!