Re: synchronized statements

From: FISH (joeking_at_merseymail.com)
Date: 11/05/03

  • Next message: Rajatheone: "Salute to all Java Gurus (?=JTapi)"
    Date: 5 Nov 2003 02:37:45 -0800
    
    

    Jonas Kongslund <dont@mail.me.at.all> wrote in message news:<XiYpb.7603$yq2.1828@news.get2net.dk>...
    > John Thorner wrote:
    > > - I would like to print all the System.out.println() statements that are
    > > related to each other (as shown above) one right after the other for
    > > the same thread. That is, I want the System.out.println() statements
    > > to be printed together for the same thread they belong to.
    >
    > A quick solution not involving the synchronized keyword is to print only one
    > string per thread, i.e. concatenate the strings.

    This doesn't stop the printing of one set of strings interrupting the
    printing of another set - I don't think System.out has any kind of
    locking mechanism to ensure two overlapping calls to println cannot
    interleave their output on the console. (Unless someone knows better?)

    I'm surprised acquiring the lock on System.out didn't work. At first
    glance I'd expect that to do the job, as all threads which entered that
    synchronized block would be required to own the lock on System.out .
    If this genuinely doesn't work (perhaps there's something lurking within
    System.out.println which releases the lock?) then the alternative is to
    replicate the behaviour with your own object. Just create a singleton
    object (a static member will do) and lock on that instead.

    -FISH- ><>


  • Next message: Rajatheone: "Salute to all Java Gurus (?=JTapi)"

    Relevant Pages

    • Re: synchronized method
      ... > Guards method execution, similar to Java's synchronized keyword. ... Under normal execution the lock will not be released because you return ... The calling thread may acquire the lock multiple times, ...
      (comp.lang.python)
    • Re: Synchronization constructs in Java and their implications
      ... one lock using the codes posted. ... synchronized keyword was the slowest one: ... Prev by Date: ...
      (comp.programming.threads)
    • Re: Efficiency about hashtable, arraylist, string and synchronization
      ... The string option is bad. ... have multiple lock objects; OK you could avoid this with a separate lock, ... but you are still making *lots* of strings. ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Charvel Model I Tuning
      ... Make sure the strings are wound on the tuners so they essentially lock in ... You will need to stretch the strings out really good before you lock ... Tune the guitar roughly to tune, ... either you're winding them wrong or you have a problem with the tuners. ...
      (alt.guitar)
    • Re: synchronized method
      ... Graham Dumpleton wrote: ... >> Guards method execution, similar to Java's synchronized keyword. ... >> L{threading.Lock} primitive as an attribute named 'lock'. ...
      (comp.lang.python)