[問題] interrupt running program on server
Hi everyone:
I got a question about interrupting a running program on server.
The following might be a little bit lengthy, I do appreciate your patience
reading this article and provide your ideas to help me resolve this problem.
Here is program description:
in a .html file I used ajax to launch a program on server
the url is like ajaxPath = "Run.jsp"; (appended with other parameters)
and in Run.jsp it contains something like
//===========================================
String StopFileName = TogetRealPath + "/StopOpt.txt";
File f1 = new File(application.getRealPath(StopFileName));
boolean success = f1.delete();
...
...
Optimizer optimizer = new Optimizer();
String CurPath = application.getRealPath(TogetRealPath);
PageResults = optimizer.RunOpt(CurPath);
On top of Run.jsp it has <%@page import= "CppOptClass.Optimizer"%>
//========================================================
This part works fine.
Here is how Stop.txt is generated:
in the same .html file I used another ajax function
with url as ajaxPath = "Stop.jsp"; (appended with other parameters)
What Stop.jsp does is the following:
BufferedWriter brw = null;
String CurUserName = request.getParameter("UserName");
String TogetRealPath = "ProjectFolder/" + CurUserName;
String CurFileName = TogetRealPath + "/StopOpt.txt";
brw = new BufferedWriter(new FileWriter(application.getRealPath(CurFileName)));
brw.write("Optimization is manually interrupted.\n");
brw.close();
Hence it generatea Stop.txt with single-line content.
and in RunOpt(String path) (member function of optimizer)
it will check periodically (every one second) if Stop.txt is there with
corresponding content. If yes, it will use "exit(-1)" to terminate.
(RunOpt(String path) is in fact implemented in C++ and hence connected by JNI)
Here is where the program is encountered:
What happened is that after launching Run.jsp, and I launched Stop.jsp. Stop.txt
is generated successfully, and RunOpt() can be
terminated successfully too. But this only works sometimes.
What happened is that sometimes I saw Stop.txt is generated, but then it got
deleted, and the RunOpt() continues to run!!!!!! In fact, based on the progress
trace, RunOpt() is not resumed, it is re-launched. That's why Stop.txt got
deleted.
But how could this possible?!?!
Again, I do appreciate your time and patience reading this article, and
I am looking forward to get response from you. Thank you very much.
C. H. Chen
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 143.215.99.58
※ cckh:轉錄至看板 Programming 09/05 02:08
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):