INFO3136 EXAM Flashcards

(91 cards)

1
Q

What is a process?

A

The entire program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a thread?

A

Small part of a process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is process based multi-tasking controlled by?

A

OS (Kernel)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is thread based multi-tasking controlled by?

A

JVM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Each thread gets its own what? (2)

A
  1. Call Stack
  2. Program counter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens if a thread cannot complete its task in the allotted time?

A

The thread is suspended

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens when a thread is suspended?

A

State data is stored in CPU cache memory until text turn

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the 2 ways to create threads in Java?

A
  1. Implement Runnable interface
  2. Extend Thread class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What method is in the Runnable interface?

A

run()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why should you never call the run() method?

A

Method is automatically invoked by JVM. If you call it explicitly then a new thread is never made

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What method is used to signal to the JVM that a thread is ready?

A

start()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What method is used to give up a thread’s remaining time?

A

yield()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What method is used to temporarily stop a thread?

A

sleep(long milliseconds)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What kind of exception can the sleep() method throw?

A

InterruptedException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the normal priority of a thread?

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What kind of scheduling involves threads of equal priorities?

A

round-robin scheduling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is it called when a low-priority thread never gets to run due to higher priority threads?

A

thread contention or thread starvation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the concurrency problem encountered in the 70’s called?

A

Lost Update Scenario

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What were created to fix concurrency issues?

A

Transaction Rules

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is an example of a synchronized data structure in Java?

A

Vector

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What kind of data structure is an ArrayList when considering threads?

A

Unsynchronized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which is faster, a synchronized data structure or an unsynchronized?

A

Unsynchronized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is it called when an unsynchronized program component allows data corruption?

A

Race Condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is it called when a class or data structure does not allow data corruption?

A

Thread-safe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the portion of the program holding the variable or data structure that can cause race conditions?
Critical Region
26
What keyword is used to prevent multiple threads from affecting the critical region?
synchronized
27
What does the keyword synchronized do?
Gives the method a lock on the data structure to guarantee exclusive access
28
What state are threads placed in when waiting for a thread with a lock to finish processing?
wait
29
What 3 methods are part of the Lock interface?
1. lock() 2. unlock() 3. newCondition()
30
What is meant by atomic in the atomic classes?
The whole operation is completed as a unit and cannot be interrupted
31
What is the keyword volatile attached to?
A Variable
32
What does the keyword volatile do?
Tells the JVM that the variable will be accessed by multiple threads, so the value should be read from main memory every time
33
Do volatile variables have locks on them?
No
34
What are the 5 states of a thread?
1. new 2. runnable/ready 3. running 4. blocked 5. terminated/dead
35
What class holds the sleep() method?
Thread
36
If a thread is put to sleep with a lock on a data structure, what happens to the lock?
Nothing
37
What does a thread that has yield() invoked on it do?
Signals to the OS that it is willing to step aside
38
What class holds the yield() method?
Thread
39
What class holds the wait( ) method?
Object
40
How many public methods are in the Object class?
7
41
What conditions must be met to use the wait() method?
Has an explicitly acquired lock on an object inside a synchronized method or block of code
42
What class holds the notify() and notifyAll() methods?
Object
43
What does notify() do?
Randomly selects a thread waiting for the object that is locked to get ready
44
What is the difference between notify( )and notifyAll()?
notifyAll() wakes all threads waiting up and allows the OS scheduler to choose which is next
45
What does the join() method do?
Stops other threads from executing until the thread that called join() is finished
46
What is the problem with calling stop( ) on a thread?
Terminated thread immediately releases its lock on any data members possibly corrupting the data
47
What method is used in place of stop()?
interrupt()
48
How does interrupt() work?
Thread that calls interrupt() sets the interrupt status boolean flag of the running thread to true.
49
When should you use a thread pool?
If you have a lot of short-lived threads that don't require a lot of I/O operations
50
What method is held in the Executor interface?
execute(Runnable r)
51
What is ExecutorService?
A sub-interface for Executor
52
What is the purpose of ExecutorService objects?
Manage threads in a pool
53
How do you create a thread pool?
ExecutorService lifeguard = Executors.newFixedThreadPool(int i);
54
What class implements Executor and ExecutorService?
Executors
55
How does a newCachedThreadPool work?
New threads are created as needed if more tasks are created, idle threads stay in pool for a maximum of 60 seconds
56
What are the 2 ways to end a thread pool operation?
1. shutdown() 2. shutdownNow()
57
What is the difference between shutdown() and shutdownNow()?
shutdown() allows all remaining threads in the pool to complete their run() code, shutdownNow() only allows the currently running threads to finish and terminate the rest
58
What is the Swing thread called?
Event Dispatch Thread
59
What is the JavaFX thread called?
JavaFX Application Thread
60
What is it called when only one thread is allowed to access components?
Thread Confinement
61
Considering single GUI thread, when is it a good idea to use a different thread?
When there are lengthy calculations
62
What listener is used to alert the event dispatch thread that a worker thread is complete?
PropertyChangeListeners
63
What are the 2 constraints for Java GUI apps?
1. Time consuming tasks should not run on the event dispatch thread 2. Swing components should only be accessed by the event dispatch thread
64
What class is used for offloading tasks from the event dispatch thread?
SwingWorker
65
What interface does SwingWorker implement?
Future< T >
66
What method is used to return the value gotten through a class that extends SwingWorker?
get()
67
What are the T and V in SwingWorker?
T - return type V - type used for intermediate results
68
What 2 methods use the V in SwingWorker?
1. publish() 2. process()
69
What SwingWorker method is analogous to the run() method of Thread and Runnable?
doInBackground()
70
What is the Model in MVC pattern?
Maintains the data to be displayed. Holds the state
71
What is the View in the MVC pattern?
Displays the data in the model
72
What is the Controller in the MVC pattern?
Handles user inputs and can update the model
73
What kind of design pattern is MVC?
Compound Design Pattern
74
Why is MVC considered a compound design pattern?
It is a composite of several simpler design patterns
75
What has to happen for the View in MVC to update automatically when the Model changes?
View has to be registered as a listener
76
What does JDBC stand for?
Java Database Connectivity
77
What 3 objects do we make when setting up a JDBC connection?
1. Connection 2. Statement 3. ResultSet
78
What changed about methods in interfaces after JDK 1.8?
Used to only be abstract (no body), but now can contain default methods
79
What does adding the "static" keyword to a default method in an interface do?
Stops it from being overridden
80
What is a SAM?
Single Abstract Method interface
81
What is an interface with only one abstract method called?
Functional Interface, or SAM
82
Can a functional interface have default methods?
Yes, but only one abstract method
83
What is a lambda expression?
Coding short-hand that can be used to represent an anonymous method
84
What is the syntax of a lambda expression?
(parameter list) -> { one or more statements to be run }
85
What is an exception?
An object that signals an error has occurred
86
What is the parent of all exception classes?
Throwable
87
What is the parent of the Runtime class?
Exception
88
Which class defines exceptions that you don't have to deal with?
Error
89
What kind of exceptions are Runtime exceptions?
Unchecked
90
What class describes checked exceptions?
Exception
91