Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
test for wait()
public class LoadingActivity extends Activity {
final byte[] lock = new byte[0];
final int goal = 3;
volatile int task = 0;
@Override
protected final void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final long time = SystemClock.elapsedRealtimeNanos();
new ViewPager(this);
new Toolbar(this);
new ActionMenuView(this);
// synchronized (lock) {
// startWork("TEST");
// try {
// lock.wait();
// } catch (InterruptedException e) {
// }
// }
Log.d("time", "" + (SystemClock.elapsedRealtimeNanos() - time));
}
public void startWork(final String task_info) {
task = 0;
new Thread(new Runnable() {
@Override
public void run() {
new ViewPager(LoadingActivity.this);
task++;
if (task >= goal) {
Log.d(Thread.currentThread().getName(), "finish task " + task_info);
synchronized (lock) {
lock.notify();
}
}
}
}, "worker").start();
new Thread(new Runnable() {
@Override
public void run() {
new Toolbar(LoadingActivity.this);
task++;
if (task >= goal) {
Log.d(Thread.currentThread().getName(), "finish task " + task_info);
synchronized (lock) {
lock.notify();
}
}
}
}, "worker").start();
new Thread(new Runnable() {
@Override
public void run() {
new ActionMenuView(LoadingActivity.this);
task++;
if (task >= goal) {
Log.d(Thread.currentThread().getName(), "finish task " + task_info);
synchronized (lock) {
lock.notify();
}
}
}
}, "worker").start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.