CPSC 233 Lecture 1: Threads
Document Summary
Use join() to cause a thread to wait for another thread to finish. Mythread t1 = new mythread() ; t1. start() ; // 2 threads now running; main and t1. // pause main thread until t1 is finished t1. join() ; Void join (long millis) this specifies time. Will wait for the thread to finish, or for the specified number of milliseconds to elapse, whichever comes first. All versions of join() may throw interrupted exception. If two or more threads access a shared resource at the same time, it may become corrupted. Assume 2 threads are simultaneously trying to deposit into the same. Bank account object. public class bankaccount { private double blance; public void deposit (double amount) { balance += amount ; Balance += amount ; actually consists of 3 steps: load balance into a register, add amount to the register, store the register"s value back into balance.