我可以强制中断线程吗? [英] Can I force an interruption of a thread?

查看:109
本文介绍了我可以强制中断线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个通过网络发送一些内容的课程。我有一些问题,因为文件发送超过10小时后没有结束,我认为连接中断。



我尝试了什么:



我虽然将发送方法放入另一个线程并尝试在超时后中断它,如果它尚未结束。但问题出在内核类中,我无法在其中查询是否检查了Therad.isinterrupted。



我可以在不问他的情况下截断一个帖子通过中断方法终止?



谢谢Lucio Menci

I wrote a class that sends some content thrugh the net. I had some issuse because a file sending didn't ended after more than 10 hours, I think for connection interruptions.

What I have tried:

I though to put the sender method into a different thread and try to interrupt it after a timeout if it wasn't ended yet. But the issue is inside a kernel class, and I cannot put into it a query to check if Therad.isinterrupted is checked.

Can I truncate a thread without ask him to terminate via the interrupt method?

Thank you, Lucio Menci

推荐答案

给出适当的安全设置在调用和接收线程中,可以使用interrupt()方法向工作线程发出信号。你仍然需要使用isinterrupted()方法检查中断的状态,所以这对于从内核模式的干净退出无济于事。



一种方法会将要发送的文件分成小块,并在超时时发送每个块。如果发送失败,或者isinterrupted()方法返回true,则工作线程可以清理并退出。
Given appropriate security settings for the calling and the receiving threads, it is possible to use the interrupt() method to signal your worker thread. You will still have to check the state of the interrupt using the isinterrupted() method, so this will not help with a clean exit from kernel mode.

One method would be to divide the file to be sent into small chunks, and send each chunk with a timeout. If the send fails, or if the isinterrupted() method returns true, the worker thread can clean up and exit.


感谢您的回复。



我的问题是我在AS400操作系统下发送了大约100个字节的数百个文件。

我的超级发送使用PrintWriter定向到java.net.URL([.. 。))。openConnection()。getOutputStream(),并通过println写入。



如果println期间连接中断,则关闭超过30秒,println正在等待杀死进程。



我担心没有解决方案。
Thank you for reply.

My problem is that I send hundreds files of about 100 bytes, under AS400 o.s..
My super send them using a PrintWriter directed to a java.net.URL([...]).openConnection().getOutputStream(), and writing into it via a println.

If there is a connection interruption during the println, and it is off over than 30 seconds, the println is waiting for a kill of the process.

I'm afraid there are no solutions.


这篇关于我可以强制中断线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆