J
John_Woo
Hi,
let's look at the following:
class GetConnection extends Thread
{
Connection con = null;
boolean done = false;
public void run()
{
try{
con = DriverManager.getConnection(...);
//notifyAll();
done = true;
}
catch(Exception e){}
}
synchronized Connection getConnection()
{
return con;
}
synchronized boolean getDone()
{
return done;
}
}
questions:
supposed in some cases it may take up to 10-20 seconds to get the
connection while other cases just takes 1-3 seconds.
what can I code in caller method, so that
1. if in 5 seconds, interrupte GetConnection thread if it has not yet
finished;
2. preventing "done" being written while trying to interrupt this
thread.
let's look at the following:
class GetConnection extends Thread
{
Connection con = null;
boolean done = false;
public void run()
{
try{
con = DriverManager.getConnection(...);
//notifyAll();
done = true;
}
catch(Exception e){}
}
synchronized Connection getConnection()
{
return con;
}
synchronized boolean getDone()
{
return done;
}
}
questions:
supposed in some cases it may take up to 10-20 seconds to get the
connection while other cases just takes 1-3 seconds.
what can I code in caller method, so that
1. if in 5 seconds, interrupte GetConnection thread if it has not yet
finished;
2. preventing "done" being written while trying to interrupt this
thread.