aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes how to use wait Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "how to use wait" Watch "how to use wait" New topic
Author

how to use wait

Paul Sun
Greenhorn

Joined: Aug 26, 2002
Posts: 19
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

Joined: Jan 30, 2002
Posts: 3451
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


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Paul Sun
Greenhorn

Joined: Aug 26, 2002
Posts: 19
Hi Michael:
Coult you tell me details about how to implement
background thread?
Thanks.
Paul.
Paul Sun
Greenhorn

Joined: Aug 26, 2002
Posts: 19
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

Joined: Jan 30, 2002
Posts: 3451

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use wait
 
Similar Threads
Can I throw exception in LOCK/UNLOCK
wait()
Discussion: Multi-Threading & EJB
Need to reduce the CPU usage when thread is running.
Implementing Lock/Unlock