Results 1 to 2 of 2
Thread: When to use semaphore in JAVA?
Feb 8, 2010, 14:33 #1
- Join Date
- Feb 2005
- Beyond the seas there is a town
- 0 Post(s)
- 0 Thread(s)
When to use semaphore in JAVA?Java 5 comes with semaphore implementations in the java.util.concurrent package so you don't have to implement your own semaphores. Still, it can be useful to know the theory behind their implementation and use.
When to use semaphore in JAVA?I shall build a boat,I shall cast it in the water,
I shall sail away from this strange earth,
Where no one awaken the heroes in the wood of love
Feb 11, 2010, 23:42 #2
- Join Date
- Jul 2005
- West Springfield, Massachusetts
- 194 Post(s)
- 2 Thread(s)
Well, I was hoping someone more knowledgeable than myself would answer so I could learn something. I don't know how similar semaphores in Java are to semaphores in PHP but I had some trouble using the PEAR Weather package a while back causing "lock" errors.
AFAIK semaphores are kind of like locking a database during transactions except they're for resources and/or memory. In other words, if 2 or more script events are interacting with it at the same time, using semaphores stops things from breaking.
I tried to learn more about it at the time so I could fix it, but it was over my head so I ended up hacking that bit of code to get things "working". It didn't matter much as I was the only one using the script (experimenting), but if I ever need to use this on a live site I really should learn about it and understand it better.