Threads Flashcards Preview

Java8 > Threads > Flashcards

Flashcards in Threads Deck (85)
Loading flashcards...
1

Thread definition

Smallest unit of execution scheduled by Operating systems

2

Process definition

A group of associated threads that execute in the same shared environment

3

Multi-threaded process?

The process that has one or more threads

4

Task?

Single unit of work performed by the thread

5

What is the System Thread?

A system thread is created by JVM and runs in the background of application. Eg.. Garbage Collector

6

Give some examples of problems that occur in System Thread? Whatexceptions do they throw?

Memory space Error.

They do not throw Exception, they throw Error

7

What is User-defined threads?

A thread created by application developer to accomplish certain tasks.

8

What are daemon threads?

Threads that do not prevent JVM from exciting when the application finishes
Eg.., Garbage Collector. If GC is the only thread that is running, then JVM shuts down

9

Concurrency?

The process of executing multiple threads at the same time is called as Concurrency

10

What does the operating systems uses to find which thread to execute?

Thread scheduler

11

What is context Switching?

It is the way of storing the current thread state and later reusing the state of the thread to continue execution

12

When is context switching be used?

When a thread doesnt complete its task in allotted time, context switch occurs

13

what are the three constant thread Static constant variable that determines the Thread priority and their values?

1. Thread.MIN_PRIORITY (1)
2. Thread.NORM_PRIORITY (5)
3. Thread.MAX_PRIORITY (10)

14

What happens when two or more threads have same priority?

The thread scheduler decides arbitrarily

15

What is the Interface to implement to create a thread?

Runnable Interface. It is a functional Interface

16

What is special about Runnbale Interfaces?

It doesnt take any arguments and doesnt return anything

17

What is the simplest way of creating a Thread?

Extending java.lang.Thread class

18

What does Java does not guarantee?

It does not guarantee the order in which the thread will be processed once the thread starts

19

What should we keep in mind on creating a thread using Runnable interface

We should pass the Runnable object to the Thread constructor

20

How should we start a thread?

We should call the 'start()' method that starts a new task for the Thread in operating systems

21

Will the below compile? What is the actual implications?

new PrintData().run();
(new Thread(new PrintData())).run();
(new ReadInventoryThread()).run();

Yes, the below compiles. But the thread created each calls the run method and thus no seperate task on the OS is executed, causing each line to wait until the previous completes

22

Polling?

It is the process of intermittently checking the data at some fixed interval

23

What method do we use generally for Polling?

Thread.sleep(long);

24

What exception does Thread.sleep method throws?

InterruptedException

25

What is ExecutorService?

In Concurrency APi, java introduces ExecutorService which creates and manages threads

26

How ExecutorService works?

We get an instance of the ExecutorService interface and then send the service tasks to be processed

27

Executor Service is an interface. How do we get the ExecutorService instance?

Java concurrency API includes a Executors Factory class that can be used to get the instance

28

What is factory Pattern?

It is the creational pattern where the underlying implementation details of object creation is hidden from us.

29

What is the package of ExecutorService?

Java.util.concurrent

30

Method to use to get the simple ExecutorService?

newSingleThreadExecutor() method in Executors class