Interrupt Java Execution in Matlab Using Ctrl-C
4 ビュー (過去 30 日間)
古いコメントを表示
Is it possible to interrupt execution of a Java method in Matlab using ctrl-c?
The only thing I could find from TMW is: http://www.mathworks.com/support/solutions/en/data/1-9389FH/index.html?product=ML&solution=1-9389FH
This solution is not ideal as:
1)Presumably it is a non-blocking call. Perhaps a secondary blocking call in Matlab would be a sufficient solution, something like: java_class.method() matlab_waiting_function()
2)When calling the method no one is going to think to call the stop thread method. The methods I have in mind may not always be long and may be nested in other functions. The above example doesn't make sense. Ideally the user would stop the call just like other Matlab calls.
One example I have in mind is rewriting urlread's read functionality. I think I can speed it up significantly. In addition one of the problems with the current behavior is the inability to interrupt retrieval of the data requested from a website. The only way to terminate reading currently is for the read to timeout. A decent answer to this question would allow me to interrupt the method.
Any thoughts?
Thanks, Jim
0 件のコメント
回答 (2 件)
v1bri
2017 年 7 月 16 日
Hey I know this thread has gone a little stale, but I wanted to post my solution just in case anyone from the future has the same question. It turns out you can call back into Matlab via JMI to poll the keyboard event queue and trigger an exception if a "Ctrl-C" is waiting. I wrote this up in more detail on my blog at https://v1ntage.io/2017/07/01/episode-001-handling-matlab-interrupts-in-java/. Let me know what you think.
0 件のコメント
Walter Roberson
2013 年 6 月 1 日
You can take care of issue #2 by providing a wrapper function that does the thread creation and thread stopping on the user's behalf.
Unless, that is, you are planning on the optimization of creating the thread, making several calls to it as a "work thread", and then stopping the thread when there is no more work to be done. If that is the plan, then depending on the architecture, a MATLAB onCleanup() might possibly be suitable to trigger the stopping. Also, such an architecture would seem to be ripe for using a MPI (message passing interface) in which the sending function could have a timer on waiting for the response, and do the thread management on timeout, instead of using control-C
参考
カテゴリ
Help Center および File Exchange で Call Java from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!