Bookmark Topic Watch Topic
  • New Topic

Java thread synchronization problem  RSS feed

 
Greenhorn
Posts: 13
IBM DB2 Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi all,

I have a problem about thread synchronization.I have 3 threads.These threads runnable class.Servlet code is below:




-----------------------------------------------------------------------------------------------------------------------
This class create thread and run method go database table and get one row.Then update one column of this row.


----------------------------------------------------------------------------------------------------------------------------------


---------------------------------------------------------------------------------------------------------------------------------

My problem is that first thread get one database record and update one row.My getAJob() method is synchronize method.But thread 1 get first row and update row, thread2 get also same row and update row.thread 3 get same row and update.But my method synchronize method.If thread 1 is in getAjob() method,thread 2 and thread3 must wait I think.I want to that for example thread1 run and run getAjob() method,thread 2 and thread 3 wait in the meantime.Then when thread1 exit getAjob() method thread2 run getAjob() method.How can I do this?How can I solve my problem?

.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please UseOneThreadPerQuestion.(⇐click) You've already got a thread for this question at http://www.coderanch.com/t/570466/threads/java/Java-thread-synchronization
 
catrine ohm
Greenhorn
Posts: 13
IBM DB2 Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
I know but Sheriff said that:" I think this question is too difficult for “beginning”, so I shall move it."
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Report post to moderator
And indeed it was moved. Not "deleted" or "erased" or anything like that, just moved. No need for another copy, then. So I'm going to lock this one, since it now contains a link to the original version.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!