完成某些特定的工作线程后如何运行线程 [英] How to run thread after completing some specific worker thread

查看:39
本文介绍了完成某些特定的工作线程后如何运行线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Swing 应用程序中创建了两个 Swing 工作线程类.它们是加载线程,保存线程

I created two swing worker thread class in my swing application. They are load thread, save thread

  1. 加载线程用于从rest服务加载数据
  2. 保存线程用于将数据推送到休息服务.

我的问题是,

  • 当我为多个实例创建多个实例时如何一一执行我的线程加载线程?

  • How to execute my threads one by one when i create more instance for load thread?

保存线程应在完成现有加载过程后运行线程

Save thread should be run after completing process of existing load thread

有没有人指导我获得这种情况的解决方案?

Does any one guide me to get solution for this scenario?

注意:我正在使用 Swing Worker 类来调用休息服务.

Note: I am using Swing Worker class to call rest services.

推荐答案

如果你想从多个线程加载数据,并在所有数据加载完后从一个线程保存这些数据.您可以尝试使用障碍.例如 CountDownLatch 可以等待,而所有加载线程完成了它们的工作.

If you want to load data from multiple threads, and save this data from one thread after ALL data will be loaded. You can try to use barriers. For example CountDownLatch can wait while all load threads finished their works.

这篇关于完成某些特定的工作线程后如何运行线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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