-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNote
More file actions
107 lines (47 loc) · 1.46 KB
/
Copy pathNote
File metadata and controls
107 lines (47 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Process: An instance of a running program.
Thread:It is a sub process or task of a process.
browser -> multiple tabs
Multithreading : It is a process of executing multiple threads
simultaneously within a single program.
Thread Creation:
i)Extending the Thread class
ii)Implementing Runnable interface
Thread Lifecycle:
i)New
ii)Runnable
iii)Running
iv)Waiting/Blocked
v)Terminated
Common Thread Methods:
start():Starts the execution of a thread.
run():Contains the code to be executed by the thread.
sleep(long millis):Pauses the execution of the current thread for specified
numbers of milliseconds.
join():Waits for the Thread to die.
isAlive():It returns true if the thread is still running.
getPriority()
setPriority()
Thread priority: 1 to 10.
default:5
Synchronization:In Java, the synchronized keyword can be used to
synchronize access to critical section of code.
i)Synchronized method:
A synchronized method ensures that only one thread can execute
it at a time for a particular object.
public synchronized void synchronizedMethod()
{
.....body....
}
ii)Synchronized block :A synchronized block of code within a method
that is synchronized on a specific object.
public void method()
{
synchronized(this)
{
//synchronized code
}
}
File I/O:
File utility class - java.nio.file - introduced in Java 7
Works with path : (instead of file)
static methods: Reading files, Writing files, Copying, Moving, Deleting files