简体   繁体   English

如何将append JSON对象转为JAVA多线程创建的json文件?

[英]How to append JSON objects to a json file created by multiple threads in JAVA?

I am having a method that returns json object. I am calling this method in multithreaded way.我有一个返回 json object 的方法。我以多线程方式调用此方法。 Now I want output (JSON Object) from each thread to be written in a single json file.现在,我希望将每个线程中的 output(JSON 对象)写入单个 json 文件中。 Is there any thread safe way to do this task.有没有线程安全的方法来完成这个任务。

Since multiple threads are trying to write in a single file it is failing.由于多个线程正在尝试写入单个文件,因此它失败了。

You can use a journaling technique.您可以使用日记技术。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM