Re: [問題] interrupt running program on server
※ 引述《cckh ()》之銘言:
: 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
^^^^^^^^^^^
I guess "re-launched" is the most critical hint to solve the problem.
Then, let's discover more information now.
Are there any loop-structures outside of your program?
Try to trace how your program is triggered and managed.
To know that, the next question is: what's your server running this program?
If it is open-source,
please download it and trace the progress more widely again.
: 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
H45
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.172.148
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):