The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Further details

Posted by Steve Que on February 24, 2002 at 10:50 PM

The code is listed in below.

In the servlet,
public void doGet(..)
{
SMAThreadPost tp = new SMAThreadPost(session, context,
input_msg, userip);
tp.start();
.....
}

In threading class,
public synchronized boolean doWrite()
{
...
while (..) {

}
}

public void run()
{
try
{
boolean status = doWrite();
sleep(1);
}
catch(InterruptedException e) {}
}

I've found that in the output file, the records are written in the following format:
log A
log A
log A
log B
log A
log B
log B
log B

So I guess the method isn't locked. Hence 2nd thread (log B) can be written before 1st thread finished (log A). Yes, everything is running in the same environment.

Thanks for your kindly help.

Steve



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us