Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
is multi-threading applicable in android programming?
Posted

1 solution

Yes, it is possible to use threads on Android.
 
Share this answer
 
Comments
dinahgee1419 2-Aug-13 6:09am    
thanks!
Fredrik Bornander 2-Aug-13 6:23am    
Happy to help.
dinahgee1419 7-Aug-13 1:37am    
i've another problem.. can you help me? it is "a thread waiting for another thread to finish before continuing.. using Java"
Fredrik Bornander 7-Aug-13 3:11am    
Here you go;


public class Program {

private static class MyThreadClass extends Thread {

private final boolean shouldWait;
private final Object someSharedResource;

public MyThreadClass(final Object someSharedResource, final boolean shouldWait) {
this.someSharedResource = someSharedResource;
this.shouldWait = shouldWait;
}

public void run() {
final long id = Thread.currentThread().getId();
System.out.println("Thread " + id + " is running.");
if (shouldWait) {
System.out.println("Thread " + id + " is waiting for sharedResource to be notified...");
synchronized(someSharedResource) {
try {
someSharedResource.wait();
System.out.println("Thread " + id + " was woken up!");
}
catch(InterruptedException e) {
System.out.println("Thread " + id + " was interrupted!");
}
}
}
try {
Thread.sleep(2000);
}
catch(InterruptedException e) {
}
System.out.println("Thread " + id + " is done.");

synchronized(someSharedResource) {
someSharedResource.notifyAll();
}
}
}

public static void main(String[] args) throws Exception {
final Object sync = new Object();

final MyThreadClass t1 = new MyThreadClass(sync, true);
final MyThreadClass t2 = new MyThreadClass(sync, false);

t1.start();
t2.start();

t1.join();
t2.join();
}
}
dinahgee1419 7-Aug-13 23:18pm    
hi.. i want it to be this way.. supposing i have 3 threads..
t1 will start first and will communicate to server thread..
after server thread responses to t1 thats the time t2 will start and so on..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900