SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    PEACE WILL WIN abalfazl's Avatar
    Join Date
    Feb 2005
    Location
    Beyond the seas there is a town
    Posts
    711
    Mentioned
    0 Post(s)
    Tagged
    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.
    http://tutorials.jenkov.com/java-con...emaphores.html

    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

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,439
    Mentioned
    160 Post(s)
    Tagged
    1 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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •