사용자가 쿼리를 실행할 수 있도록하는 응용 프로그램을 개발했습니다. 사용자가 쿼리를 입력하고 실행 버튼을 클릭하면 컨트롤이 RMI 서버로 전달되어 스레드를 시작합니다.실행을 중지 할 수 없습니다
사용자는 다른 쿼리를 차례대로 실행할 수 있어야하며 각 쿼리는 다른 스레드에서 실행됩니다.
스레드 실행을 중지 할 수 없습니다. 실행되는 동안 또는 전달 된 스레드 ID를 기준으로 버튼 클릭 이벤트에서 실행을 중지하고 싶습니다. 나는 이
public class AcQueryExecutor implements Runnable {
private volatile boolean paused = false;
private volatile boolean finished = false;
String request_id="",usrnamee="",pswd="",driver="",url="";
public AcQueryExecutor(String request_id,String usrnamee,String pswd,String driver,String url) {
this.request_id=request_id;
this.usrnamee=usrnamee;
this.pswd=pswd;
this.url=url;
this.driver=driver;
}
public void upload() throws InterruptedException {
//some code
stop();
//some more code
}
public void run() {
try {
while(!finished) {
upload();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void stop() {
finished = true;
}
}
가 내 knowlegde의 p.killJob (까지
public class ExecutorServer extends UnicastRemoteObject implements ExecutorInterface
{
public ExecutorServer()throws RemoteException
{
System.out.println("Server is in listening mode");
}
public void executeJob(String req_id,String usrname,String pwd,String driver,String url)throws RemoteException
{
try{
System.out.println("Inside executeJob.wew..");
AcQueryExecutor a=new AcQueryExecutor(req_id,usrname,pwd,driver,url);
Thread t1 = new Thread(a);
t1.start();
}
catch(Exception e)
{
System.out.println("Exception " + e);
}
}
public void killJob(String req_id)throws RemoteException{
logger.debug("Kill task");
AcQueryExecutor a=new AcQueryExecutor(req_id,"","","","");
a.stop();
}
public static void main(String arg[])
{
try{
LocateRegistry.createRegistry(2007);
ExecutorServer p=new ExecutorServer();
Naming.rebind("//localhost:2007/exec1",p);
System.out.println ("Server is connected and ready for operation.");
}catch(Exception e)
{
System.out.println("Exception occurred : "+e.getMessage());
e.printStackTrace();
}
}
}
RMI 클라이언트
ExecutorInterface p=(ExecutorInterface)Naming.lookup("//localhost:2007/exec1");
System.out.println("Inside client.."+ p.toString());
p.executeJob(id, usrname, pswd);
p.killJob(id);
}
에게 스레드를 시작하는 곳에서
RMI 서버 클래스) 실 거예요 호출됩니다
코드 아래에 노력하고 있습니다 executeJob()이 종료 될 때까지. 실행되는 동안 실행을 중지하고 싶습니다.
스레드를 어떻게 중지합니까? 왜 upload() 메서드는 중간에 stop() 메서드를 호출합니까? –
사이에 실행되는 동안 스레드를 멈출 수 있는지 확인하고 싶습니다. 내 정지 블록이 작동하는지 확인하십시오. – happy
'upload() '명령이 완료 될 때까지 스레드가'stop() '방법, 그렇지? 거기에서 중단하기 위해서'upload()'메쏘드 안에서'finished' 플래그를 폴링해야 할 것입니다. – erickson