COP4600_28-5 - Administrivia * Monday is a holiday Java...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Administrivia * Monday is a holiday Java threading Cancelling a thread Since stop() is deprecated -- it's unsafe: can lead to deadlock -- how does one safely cancel a thread Part I: signaling the thread to be cancelled A thread will be interrupted by another thread targetThread.interrrupt(); interrupt() * does not force the receiver to do anything! * it says to the target thread, "hey you! pay attention!" * a thread that is sleep()- ing or wait() -ing will be yanked out of the "blocked" state and an InterruptedException will be thrown (for it to handle), and the thread will be made "runnable" - otherwise , that thread's interrupt flag will be set. Part II: responding to the signal Threads are usually written so that they are * performing a set of sequential (sub)tasks, or * repeatedly performing a (set of) task(s). In either case, we want to write code that does some work and periodically asks the question, "should I stop?" Thread.interrupted() * checks the state of the currently executing Thread's interrupt flag - returns true IFF the interrupt flag was set - the flag is cleared prior to Thread.interrupt() 's return. Example: canceling an "iterative" thread The thread is performing the same task repeatedly while( ! Thread.interrupted() ) { // do work
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2011 for the course ECON 2023 taught by Professor Rush during the Spring '08 term at University of Florida.

Page1 / 4

COP4600_28-5 - Administrivia * Monday is a holiday Java...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online