Created
April 8, 2015 06:28
-
-
Save kenaiX/4de5c370e42d25230ceb to your computer and use it in GitHub Desktop.
test for wait()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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