We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我再学习这个代码的时候,遇到主线程一直不退出。想请问下老哥shutdown是在哪儿呢。 我加在了await的后面。
The text was updated successfully, but these errors were encountered:
工具类里的shutdown的方法要改一下, 这是我改的代码, 改完之后可以在start()后,直接调用shutdown()方法, executorservice.shutdown()方法是优雅停止,会先判断任务是否执行完成, 任务未完成则会等待任务执行完成再终止线程.
`` public void shutdown() { this.executorService.shutdown(); try { // 等待所有线程执行完成才释放资源,防止读取到一半释放资源造成文件句柄丢失问题 for ( ; ;) { if (executorService.isTerminated()) { this.rAccessFile.close(); System.out.println("读取任务结束, 释放资源"); break; } // 停5秒进入下一次判断是否任务执行完成 Thread.sleep(5000); } } catch (Exception e) { System.out.println("任务结束时, 关闭访问异常"); } }
private static void testMultiThreadRead() { BigFileReader.Builder builder = new BigFileReader.Builder("D:\\soft\\OneDrive\\桌面\\fsdownload\\test.txt", new MyFileHandle()); builder.withTreahdSize(2) .withCharset("utf-8") .withBufferSize(1024); BigFileReader bigFileReader = builder.build(); bigFileReader.start(); bigFileReader.shutdown(); }
Sorry, something went wrong.
No branches or pull requests
我再学习这个代码的时候,遇到主线程一直不退出。想请问下老哥shutdown是在哪儿呢。
我加在了await的后面。
The text was updated successfully, but these errors were encountered: