多线程到达,最后一个应该做处理 [英] Multiple threads arrive, the last should do the processing

查看:90
本文介绍了多线程到达,最后一个应该做处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个日志记录,其中多个线程可以写入一个List日志.最后一个线程应将List的内容写入文件.因此,最后写入List的线程应将List刷新到文件中.最好的方法是什么?

I'm implementing a logging where multiple threads can write into one List of log. The last thread should write the contents of the List to a file. So the thread which is the last to write into the List should flush the List into a file. What is the best way to accomplish this?

对于List,我只需要对多个作者和一个读者有效的并发类之一.

For the List I just need one of the concurrent classes that is efficient for multiple writers and one reader.

推荐答案

对于我来说,简单的解决方案是实现Closeable,然后使用close方法进行刷新.

In my case the simple solution was to implement Closeable and then do the flushing in the close method.

这篇关于多线程到达,最后一个应该做处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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