Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

[MultiThread] :: Help Please  RSS feed

 
Luka Mar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guru , it's really just that I'm venturing with Java, and specifically on API 1.5 and then upgrade to version 6.
Now, I find myself in the study of concurrent programming in Java and in particular the use of threads, semaphores, locks etc. etc.
Would someone be kind enough to provide an example of code that do the following ... in order to understand the proper methodology to follow. If you do not ask too much with a minimum of comment ... otherwise it's OK to try to figure out without following the flow ...

Starting from a data structure like array of strings, in which items could be, for example, "00aabbcc", "11ddeeff ... This vector will contain immutable, that is where the elements never change. Once the carrier will always remain so in terms of data length.

On all elements must be carried out two operations more than once, say "1 to N". These operations will also be carried out simultaneously on multiple items but not on the same item.
I make an example if the item "00aabbcc" I'm running the operation "A", I can not perform the operation on the same element "B" unless the operation "A" is not over, but I can run many more simultaneous operations on other elements of the vector, but always following the link on an item that can only execute a transaction at a time.

I started reading the documentation, but honestly ... I begin to lose between traffic lights, lock synchronization etc. etc.
Someone smarter than me, could you help me?

Thanks a lot.
P.s.: Sorry for my bad English use an automatic translator (well I have to study English / American)
 
Luka Mar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UP
 
Henry Wong
author
Sheriff
Posts: 22840
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luka Mar wrote:
P.s.: Sorry for my bad English use an automatic translator (well I have to study English / American)


Something has definitely been lost in translation. Could not follow you when you started talking about "operation A" and "element B" at all -- not even close. Could you try again? and this time, maybe with some diagrams?

Henry
 
prem pillai
Ranch Hand
Posts: 87
Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the program present in the thread http://www.coderanch.com/t/522780/threads/java/wait-notify Try to read and understand that code (there is a bug, but see Henry Wong's comments for the fix). May be you can debug it in an IDE like eclipse; that would help you to get the control flow properly.

For semaphores ; there is an example java program available in the link http://en.wikipedia.org/wiki/Dining_philosophers_problem.




Regards
Prem
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!