我正试图停止read。 在阻止我的read子时, exception子被打断。
如果read然放弃中断的例外,我可以做些什么。 难道应该赶上它,什么东西或做什么?
我正试图停止read。 在阻止我的read子时, exception子被打断。
如果read然放弃中断的例外,我可以做些什么。 难道应该赶上它,什么东西或做什么?
你们不应只是停止read。 我做的事情大多是在Thread的阶级中制造一种公众(或许是静态的)变数,表明read子何时应当停止。 因此,就像声明一样。
public volatile bool shouldStop = false;
然后,在你read子的每个周期结束时,你可以检查你是否需要放弃(从 while或 something起)。
read可以非常 an忙地处理! 仅仅在表面上要求中断/停止功能是可能的,但大多是不必要的。
There is a reason .stop() and .suspend() were deprecated and should not be used. This article is relevant: http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html
我也引用 Java:
Deprecated. This method is inherently unsafe. Stopping a thread with Thread.stop causes it to unlock all of the monitors that it has locked (as a natural consequence of the unchecked ThreadDeath exception propagating up the stack). If any of the objects previously protected by these monitors were in an inconsistent state, the damaged objects become visible to other threads, potentially resulting in arbitrary behavior. Many uses of stop should be replaced by code that simply modifies some variable to indicate that the target thread should stop running. The target thread should check this variable regularly, and return from its run method in an orderly fashion if the variable indicates that it is to stop running. If the target thread waits for long periods (on a condition variable, for example), the interrupt method should be used to interrupt the wait. For more information, see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.
你们应当找到某种方式(无论是某些共同变量还是其他方式)来nch笑你的read子,以便read子能够结束。
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...