Threads with j2me

HI ,

I have been struck with the implemenation of multithreading in j2me.

Flow is like this.

1)Thread A (main thread) spawns a new thread B.

2)Thread B reads from the contact list (using PIM API) and populates the hash map object, a global variable.

3)Thread A reads this global Hash map and then disply.

But threads are not getting synchronised in the above way.Thread A starts reading hashmap before the thread B could populate the same....

Please help me out to solve this issue.

[531 byte] By [j2m2foruma] at [2007-11-27 8:15:47]
# 1
Simple: don't use threads.Why would you have threads if you want to so stuff sequentally?
deepspacea at 2007-7-12 20:00:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Read About Thread.join().null
Kuldipa at 2007-7-12 20:00:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

Use a gate type lock, synchronize on the lock on thread A and wait. When thread B is done populating, use Thread.notify to notify Thread A that it can resume.

int[] lock = {};

...

// in thread A

synchronized (lock) {

lock.wait();

}

// in thread B

synchronized (lock) {

// done populating

lock.notify();

}

jonathan.lea at 2007-7-12 20:00:37 > top of Java-index,Java Mobility Forums,Java ME Technologies...