Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 使用Executors时的当前线程计数。newSingleThreadExecutor().execute_Multithreading - Fatal编程技术网

Multithreading 使用Executors时的当前线程计数。newSingleThreadExecutor().execute

Multithreading 使用Executors时的当前线程计数。newSingleThreadExecutor().execute,multithreading,Multithreading,我正在使用Executors.newSingleThreadExecutor().execute来执行我的方法,在我的方法中,我将文件复制到驱动器,复制后,我将重命名我的文件。在文件名中,我必须将其命名为当前线程数,即如果是第一个线程,我的文件名将是xxx_1,xxx_2,以此类推。是否可以实现它?(我的文件的命名将在我的调用方法中)如果是,请任何人向我建议解决方案。提前谢谢。您可以在处理方法(在单独线程中运行的方法)中使用静态变量并递增它。您能试试吗?然后发布您的代码。Executor Exe

我正在使用Executors.newSingleThreadExecutor().execute来执行我的方法,在我的方法中,我将文件复制到驱动器,复制后,我将重命名我的文件。在文件名中,我必须将其命名为当前线程数,即如果是第一个线程,我的文件名将是xxx_1,xxx_2,以此类推。是否可以实现它?(我的文件的命名将在我的调用方法中)如果是,请任何人向我建议解决方案。提前谢谢。

您可以在处理方法(在单独线程中运行的方法)中使用静态变量并递增它。

您能试试吗?然后发布您的代码。Executor Executor=Executors.newSingleThreadExecutor();count++;executor.execute(new DownloadService(file,old.getTitle(),old.getid(),count));我的文件将在其名称中包含Title\u Id\u count!!我也这样做了。在使用executors时,有没有办法知道线程的计数?