Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use wait

 
Paul Sun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I am using wait method when a record is locked
by other client. But when thread is waitting, client still continue doing next steps, refresh
the JTable depend on result of modification. In
fact, at this time thread does not work.
If I need to return a message to client when
wait method run?
Thank you.
Paul Sun.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
To avoid the problem you describe, you need to make database calls in a background thread. I used the Observer pattern to be notified when a thread completed.
Hope this helps,
Michael Morris
 
Paul Sun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael:
Coult you tell me details about how to implement
background thread?
Thanks.
Paul.
 
Paul Sun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael:
I have another question. If you access db by way of running a thread in background, what does client do at that time? show a message or do nothing?
:roll:
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If you access db by way of running a thread in background, what does client do at that time? show a message or do nothing?

It just continues accepting/processing user input. If you have one or more background threads booking, you need to make that until those threads complete, that you don't allow those particular records to be booked again.

Coult you tell me details about how to implement
background thread?

My DataFacade implemented Runnable, so when the client wanted to book a flight it went thru something like this:

The DataFacade mapped booking requests to threads so that multiple bookings could occur asynchronously. DataFacade also extended Observable and the object that created the booking threads implemented Observer, so whenever a thread completed DataFacade called setChanged() and notifyObservers() and removed the thread from the map.
Hope this helps,
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic