1. Trang chủ
  2. » Giáo án - Bài giảng

Lab Thread 1

4 127 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 4
Dung lượng 245,63 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

The first approach for creating a thread by extending the Thread class b.. Exercise 2: Thread state.. Exersice 3: Method of the Thread class 4.. Exercise 4: Managing Thread: Priority...

Trang 1

Bai Lab Thread 1

I Part 1: 1.5 hour

1 Exericise 1: Creating a thread

a The first approach for creating a thread by extending the Thread class

b The second approach for creating threads, where the Runnable interface is implemented

2 Exercise 2: Thread state This program show some of the states that a thread can have

Trang 2

3 Exersice 3: Method of the Thread class

4 Exercise 4: Managing Thread: Priority

Trang 3

5 Exercise 5:

a Daemon thread

b

c

d To illustrate how JVM can exit when deamon thread are alive, a single thead is created and its Daemon property

is set to true by invoking the setDaemon() method The user thread is converted to a daemon thead Now when this thread starts executing, the main method finishes its execution Thus the only thread running will be a daemon thread At this instant, the JVM exists

The same example could be tested by omitting the setDaemon() method In that case, the thread would be a normal user thread and as long as it is executing, the JVM cannot exit Hence the program will continue

indefinitely

II Part 2: 0.5 hour

Trang 4

Write a program MulThread that create 2 threads, one thread with the name Marimba and the other thread named

as Jini Each thread should display its respectivename and execute after a gap of 1000 miliseconds Also the threads should display a number indicating the number of time it got a chance to execute

Hint: Use setName() method to set the name of the thread

Note: Must be used two approach to create a thread

Ngày đăng: 13/05/2014, 11:15

Xem thêm

w