Java线程生命周期(Java thread life time)
假设我有以下内容:
public class A { Thread t = new Thread(new Runnable() { @Override public void run() { B b = new B(); } }); } class B{ // long running process and alot of code }
问题是,B类所做的所有过程和工作都是在线程t下进行的,或者只是在创建了B类的对象并且B类的工作开始时才更有效?
Suppose I have the following:
public class A { Thread t = new Thread(new Runnable() { @Override public void run() { B b = new B(); } }); } class B{ // long running process and alot of code }
The question is that all process and work that class B does goes under thread t or just when the object of class B is created and work of class B starts t is no more available?
原文:https://stackoverflow.com/questions/32167248
最满意答案
不,将CTRL-C字符传输到您的进程中将不起作用,因为CTRL-C键击被终端捕获并转换为发送到进程的终止信号。
CTRL-C的正确字符代码(ASCII码)是3号代码,但如果你将它回显给你的程序,它只会从它的标准输入接收字符。 它不会导致进程终止。
如果您想要简化查找和查杀流程的任务,您可以使用如下所示的内容:
./program_that_does_not_terminate & pid=$! sleep 20 kill ${pid}
$!
将为您提供上次启动的后台进程的进程ID。No, piping a CTRL-C character into your process won't work, because a CTRL-C keystroke is captured by the terminal and translated into a kill signal sent to the process.
The correct character code (in ASCII) for CTRL-C is code number 3 but, if you echo that to your program, it will simply receive the character from its standard input. It won't cause the process to terminate.
If you wanted to ease the task of finding and killing the process, you could use something like:
./program_that_does_not_terminate & pid=$! sleep 20 kill ${pid}
$!
will give you the process ID for the last started background process.
相关问答
更多-
这实际上是特定于某些版本的echo (我很确定\c来自SysV,而-n版本是BSD-ism)。 它只是意味着不输出结尾的换行符。 That's actually specific to some versions of echo (I'm pretty sure that \c came from SysV while the -n version was a BSD-ism). It simply means don't output the trailing newline.
-
回声控制C字符(Echo Control C character)[2024-04-12]
不,将CTRL-C字符传输到您的进程中将不起作用,因为CTRL-C键击被终端捕获并转换为发送到进程的终止信号。 CTRL-C的正确字符代码(ASCII码)是3号代码,但如果你将它回显给你的程序,它只会从它的标准输入接收字符。 它不会导致进程终止。 如果您想要简化查找和查杀流程的任务,您可以使用如下所示的内容: ./program_that_does_not_terminate & pid=$! sleep 20 kill ${pid} $! 将为您提供上次启动的后台进程的进程ID。 No, piping ... -
有控制字符,你似乎喜欢一个空间。 例如看看ASCII 0-31 http://ascii-code.com/ 也许尝试复制粘贴到Windows编辑器(而不是Notepad ++或word)并粘贴回您的json数据。 there are control characters, which seems to you like a space. for example have a look at the ASCII 0-31 http://ascii-code.com/ Maybe try to copy-pa ...
-
好的。 我找到了答案。 COMException(0x80004005):错误HRESULT E_FAIL发生,因为我试图从COM线程访问主线程对象。 以下是我的所作所为。 public partial class Form1 : Form { WebBrowser browser; SHDocVw.WebBrowser_V1 browserV1AceCounter; byte[] bPostData; string sHeader; string sURL; ...
-
for循环的目的是将\ n添加到字符串中。 循环之后你做 Password = [Password stringByReplacingOccurrencesOfString:@"\n" withString:@""]; 这取代了添加的\ n,没有=删除它们。 BTW:使用15 \ n的字符串文字更容易,然后将填充长度的子字符串添加到源字符串: int padding = 16 - ([Password length] % 16); password = [password appendString:[@" ...
-
您正在搜索的字符转义特定于Perl正则表达式。 为了您的目的,我建议您传递ctrl-M和ctrl-P的hex value 。 $exp->send("\x10"); # ctrl+P $exp->send("\x0D"); # ctrl+M 更新(测试): $exp->send("\x10"); # ctrl+P $exp->send("\n"); # send newline sleep 2; # wait for prompt $exp->expect($timeout, '$ '); $exp ...
-
正如评论中所见 ,这解决了这个问题: grep $'\01' file As seen in comments, this solved the issue: grep $'\01' file
-
你需要引用和逃避: set={1,2,3,"\'4\'"} 请注意,它与{1,2,3,4}一起使用,因为它是数字。 对于字符串,您还需要引用: {1,2,3,'a'} $ echo {1,2,3,'a'}{1,2,3,'a'} 11 12 13 1a 21 22 23 2a 31 32 33 3a a1 a2 a3 aa 然后转义是处理bash -c与值的执行。 根据您的评论,您的最终脚本是: set={"\(","\)","\,"} group=3 for ((i=0; i<$group; i++)) ...
-
您不需要几百行批处理文件来执行替换就像这一样简单。 下面的两行批处理文件也是如此: @set @a=0 // & cscript //nologo //E:JScript "%~F0" < myfile.txt > out.txt & move /Y out.txt myfile.txt & goto :EOF WScript.Stdout.Write(WScript.Stdin.ReadAll().replace(/HEADER/g,"\x0C")); 有关正则表达式语法的进一步说明,请参阅此页面 ...
-
控制gdb tui中的字符(Control character in gdb tui)[2023-08-26]
TUI密钥绑定有时不起作用,请参阅https://stackoverflow.com/a/30763087/72178和https://stackoverflow.com/a/30763033/72178 。 作为一种解决方法,您可以在最新版本的gdb中使用这些命令: tui enable tui disable TUI Key Bindings sometimes do not work, see https://stackoverflow.com/a/30763087/72178 and https: ...