如何暂停然后恢复一个帖子? [英] How pause and then resume a thread?

查看:87
本文介绍了如何暂停然后恢复一个帖子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I state that I read about thread, but I've never used. So I ask to you :)

我有两个主题: A B
其中 A 管理GUI, B 管理逻辑。

I have two thread: A and B, where A manages the GUI, and B manages the logic.

我会从 A 开始。

然后当 A 绘制GUI时,我会暂停它,等待 B 将X点到达run方法。

Then when A draw the GUI, I would pause it, to wait B that reach a point X into run method.

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

And when B reach the X point into run method, I pause B, and resume A.

A B 分享一些变量来管理GUI和逻辑......

A and B share some variable to manage the GUI, and the logic...

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

Can I do it? if yes, how? :)

推荐答案

使用 wait() notify()方法:


wait() - 使当前线程等到另一个线程调用此对象的
notify()方法或notifyAll()方法。

wait() - Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

notify() - 唤醒正在此对象监视器上等待的单个线程。

notify() - Wakes up a single thread that is waiting on this object's monitor.

这篇关于如何暂停然后恢复一个帖子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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