java如何通过不同的进程在两个线程中同时处理?
通过调用一些方法,我从DB获得了一个列表X。现在我将列表拆分为两个单独的列表A&;B根据某些标准
必须以不同的方式处理这两份清单。但是我希望在这个时候开始处理这两个列表。不想等待并开始处理第二个
请建议最好的方法是什么
我的是SpringWeb应用程序。这仅适用于特定的服务
提前谢谢
你可以在下面搜索框中键入要查询的问题!
通过调用一些方法,我从DB获得了一个列表X。现在我将列表拆分为两个单独的列表A&;B根据某些标准
必须以不同的方式处理这两份清单。但是我希望在这个时候开始处理这两个列表。不想等待并开始处理第二个
请建议最好的方法是什么
我的是SpringWeb应用程序。这仅适用于特定的服务
提前谢谢
# 1 楼答案
若要处理多个线程,应同步列表。请参阅下面的代码,以在同步块和线程安全中的子列表之间拆分列表
# 2 楼答案
为了能够作为程序的异步元素处理某些内容,您必须为该操作启动新线程。Java中存在支持这种类型操作的特殊API
您将需要使用类Thread和接口Runnable
You should read the tutorial
# 3 楼答案
你的问题太模糊了。一般的答案是为每个列表生成一个
Thread
并对其进行处理(未测试,但应能正常工作)