相关疑难解决方法(0)

如何暂停然后恢复一个线程?

我声明我读过线程,但我从未使用过.所以我问你:)

我有两个线程:AB,其中A管理GUI和B管理逻辑.

我会先说A.

然后在A绘制GUI时,我会暂停它,等待B到达X点进入run方法.

B达到X点进入运行方法时,我暂停B,然后恢复A.

AB共享一些变量来管理GUI,逻辑......

我可以做吗?如果有,怎么样?:)

java multithreading

40
推荐指数
2
解决办法
8万
查看次数

在java中暂停线程

我想知道是否有人可以帮助我如何实现一个在后台无限运行的线程,直到用户按下p,此时它会暂停其他线程并按下r恢复其他线程.这是一些代码

一些主要对象

public class CardGame
{
   static Player[] players;
   static int handSize;
   static Queue<Card>[] playingDeckArray;


public static void main(String[] args){
        Scanner reader = new Scanner(System.in);

        System.out.println( "\nHello, how many players would you like" );
        int playersNum = Integer.parseInt(Checks.userInputCheck( "\\d" ));
        System.out.println( "\nHow many cards should each player begin with" );
        int handSize = Integer.parseInt(Checks.userInputCheck( "\\d" ));
        System.out.println( "\nWhich strategy would you like to use 1 or 2" );
        int strategy = Integer.parseInt(Checks.userInputCheck( "[12]$" ));

        Logger.createDeck( playersNum, handSize );

        makePlayers( playersNum, …
Run Code Online (Sandbox Code Playgroud)

java multithreading

2
推荐指数
1
解决办法
286
查看次数

标签 统计

java ×2

multithreading ×2