• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread, update twice  RSS feed

 
sing
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why my code always update at least twice into database at the first running but after that it will update once. I guess the problem is from synchronized..Can someone help me? Thank you.
public class sample
extends javax.servlet.http.HttpServlet
implements Runnable
{
private static Object obj = new Object();
public sample()
{
}

public void init()
throws javax.servlet.ServletException
{
new Thread(new sample()).start();
}
public synchronized void run()
{
while (true)
{
try
{
findPath();
Thread.sleep(1000);
}
catch (Exception e) { System.out.println(e);}
}
}
private void findPath()
throws Exception
{
try
{
if(validateComplete())
{
..... //call other methods
saveContentDB();
}
} catch (Exception e) {
throw new Exception(e.getMessage());
}
}
private boolean validateComplete()
throws Exception
{
boolean success = false;

......

return success;
}

private void saveContentDB()
throws Exception
{
}
}
[ October 23, 2002: Message edited by: Steffy Sing ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!