Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reservation problem!

 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
I've made the reservation system as follows:
I have a class that asks for the number of seats to reserve. After returning from this class, a thread is created. This thread makes the reservation. After the thread.start() I have a call to a method that refreshes the data to be show in the JTable.
My problem is, when I book a seat, the refresh data method is executed before the thread
The code is as follows:

I've tried with the .isAlive() method from the thread, but this just hangs the program, as the thread is allways alive, even after it has finished the execution!
What is the best way to solve this?
Thanks,
Miguel
 
Matt Ghiold
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to make it simpler =). You really don't need a thread going off and doing the registration for you.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My problem is, when I book a seat, the refresh data method is executed before the thread.

Move your "refresh" method to the end of the run() method of the "reserve" thread.
Eugene.
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
Problem solved. Instead of reservation class implementing the runnable interface, it is now a normal class. I've changed the reservation method in the main window so that it creates the thread and implements the runnable as a abstract class and it's here that i call the reserve folowed by the refresh.

Now it works .
I've also made the same for the read of the database (refreshTableData() method).
Thanks,
Miguel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic