CPSC 233 Lecture 1: Threads

99 views2 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers