简体   繁体   English

Java 中的响应式批处理

[英]Responsive batch processing in Java

I like the fact that threads can share some resources but they need to release their private resources in the end.我喜欢线程可以共享一些资源,但它们最终需要释放自己的私有资源这一事实。 Meantime, some computations may be obsolete and you kill them, using Task Manager.同时,某些计算可能已经过时,您可以使用任务管理器杀死它们。 I am looking for the same thing done in one JVM process.我正在寻找在一个 JVM 进程中完成的相同的事情。

You say that thread.stop is unreliable and propose that my thread polls the interrupted flag instead .您说thread.stop不可靠建议我的线程改为轮询interrupted标志 But, polling is not efficient, right?但是,轮询效率不高,对吧? You do not want neither performance penalty nor polluting your code with ubiquitous if (interrupted) blocks.您既不希望性能损失,也不希望无处不在的if (interrupted)块污染您的代码。 What is going to be the best appropriate option here?这里什么是最合适的选择?

Killing one process in an application that is composed of several interacting processes can be dangerous, but it is not usually as dangerous as killing a thread.在由多个交互进程组成的应用程序中杀死一个进程可能很危险,但通常不如杀死线程那么危险。

The ways in which one process depends on the state of another often are more limited.一个进程依赖于另一个进程的方式通常更为有限。 If the processes only interact through network communication, it probably won't be hard to design an application that can gracefully recover from having one of its processes killed.如果进程仅通过网络通信进行交互,那么设计一个可以从其中一个进程被杀死后正常恢复的应用程序可能并不难。 Likewise, if the processes interact through a shared transactional database.同样,如果进程通过共享事务数据库进行交互。

It gets harder to handle a KILL safely if the processes interact through shared files.如果进程通过共享文件进行交互,则安全处理 KILL 会变得更加困难。 And it gets pretty close to impossible to guarantee the safety of an arbitrary KILL if the processes interact via shared memory.如果进程通过共享内存进行交互,则几乎不可能保证任意 KILL 的安全性。

Threads always interact via shared memory.线程总是通过共享内存进行交互。 A KILL that can't be handled, could come at any time.不能处理的KILL,可以随时来。 There's just no way to guarantee that killing some thread won't leave the whole program in a corrupt state.没有办法保证杀死某个线程不会使整个程序处于损坏状态。

That's why t.stop() is deprecated in Java.这就是t.stop()在 Java 中被弃用的原因。 The real question should be, "why did they ever implement t.stop() in the first place?"真正的问题应该是,“他们为什么要首先实现t.stop() ?”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM