• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Beginner Thread Question

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, one thing lacking for me is one concept of threads. For example, say i have a customer class that has methods to deletecustomer, addcustomer, editcustomer etc.
I make this runnable.

Then say for instance, i have 3 users. they all want to work on three different customers at the same time.
So
user 1 wants to delete a customer
user 2 wants to add a customer
user 3 wants to edit a customer.

Making a new thread for these is fine. However, one concept i don't understand is what to write in the run method??

I can't type addcustomer, deletecustomer or editcustomer, as these may not always be needed. Can someone help me to understand this please?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I can't type addcustomer, deletecustomer or editcustomer, as these may not always be needed. Can someone help me to understand this please?



Let's forget about threads for a second...how would you deal with a *single* user, who may decide to add, delete, or edit customers?

Henry
 
Sumair Ahmed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

I can't type addcustomer, deletecustomer or editcustomer, as these may not always be needed. Can someone help me to understand this please?



Let's forget about threads for a second...how would you deal with a *single* user, who may decide to add, delete, or edit customers?

Henry




I suppose, i would have a class for the model, called clsCustomer with getForename, getSurname etc.
Then in that class i would have a method called addCustomer with parameters.

Then in the controller, when the user clicks on a button, i would then call the addcustomer method along with the correct parameters.
 
Sumair Ahmed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take this quick mock up.





How would i implement a runnable to the following. Any comments /ammendments to design more than welcome. I'm here to learn.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What is it that you have said so far ... that will work in the main() method, but won't work in the run() method? In theory that is?

Henry
 
Sumair Ahmed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not that, what i am trying to understand is

What do i write in the run method for the thread if there are multiple tasks.

Say User 1 wants to update a member
user 2 wants to add one
user 3 wants to delete a member

Imagine all 3 trying to do this at same time. Updating seperate records at same time.

I need a thread.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What do i write in the run method for the thread if there are multiple tasks.



The same exact thing that you would put in the main method -- it would check its model for the customer that it is handling, see what needs to be done, and call the correct methods. Are you expecting it to be something completely different?

Of course, this will likely be server code, since it would be silly to have a client that handles multiple users, as only one user can use a GUI at one time.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Imagine all 3 trying to do this at same time. Updating seperate records at same time.



Of course, you need to make the code that share data (including the DB) be thread safe. But this is related to synchronization at a data layer -- it doesn't require special techniques in the run() method. Synchronization can get complex, but there are also some classes that can help with this too.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic