Module 1 Flashcards

1
Q

What is the difference between multitasking and multithreading?

A

Multitasking is when several applications seem to run at the same time.
Multithreading is a form of multitasking within an application.

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

What is concurrent programming?

A

Concurrent programming is to make two or more task seemingly (almost) execute at the same time. (Sharing the computers CPU)

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

What is parallel programming?

A

Parallel programming is when two or more tasks run exactly at the same time. (Not sharing the computers CPU).

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

What is a process?

A

An instance of an application being executed.

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

What does a process consist of?

A

Program instructions to the machine.
Stack memory (call stack) - to keep track of active methods.
A heap memory.
A program counter (register).
Other resources, security information, information about the state of the process etc.

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

Is a process isolated from other processes?

A

Yes, a process runs in it’s own address space managed by OS and is totally isolated from other processes.

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

What is a thread?

A

A single sequential flow of control within a program

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

What does all threads within the same process share?

A

Adress space, code and data

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

What’s the difference between threads and processes?

A

A process is the execution of a program, isolated from other processes. It runs in its own memory space.
A thread runs within the address space of a process. It is a execution of the whole or parts of a program. Threads share the process memory area.

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

Does every process has a thread?

A

Yes, every process has at least one thread. More threads can be created in the process.

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

What is concurrency?

A

A property of a computing system in which several tasks are executing simultaneously. Systems are (or seem to be) progressing at the same time.
Running several programs at the same time is an example.

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

Name two types of concurrency

A

Multithreading and parallel programming

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

What is a sequential application?

A

A sequential application has one single thread of execution.

A sequence of statements that are executed one after another.

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

True or false:

A concurrent application has multiple threads of execution.

A

True

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

True or false:

A sequential application has one single thread of execution.

A

True

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

How can parallelism be achieved in an application?

A

By splitting the application into smaller tasks where they can be executed in parallel.

17
Q

Can both concurrency and parallelism be achieved in a single-core CPU?

A

No, concurrency can but not parallelism.

18
Q

What is the difference between parallelism and concurrency?

A

Parallelism: Running exactly at the same time. Two applications run purely parallel, each in a separate processor.

Concurrency: Running seemingly at the same time. The processor shares its time to program with so short intervals that it gives the users the illusion of programs running in parallel.

19
Q

True or false:

Parallelism can be considered as a form of concurrency.

A

True

20
Q

What are the main advantages with multithreading?

A

Performance and responsiveness.

21
Q

Name some typical thread states.

A

Ready
Running/active
Blocked/waiting
Terminated

22
Q

What are the two ways to create and start a thread in java?

A
Provide a Runnable object by implementing the interface Runnable which defines a single method called run.
Subclass the Thread class and override the run method.
In both cases Thread.start() is used to start the thread.
23
Q

What does the Thread.join() method do?

A

It allows one thread to wait for the completion of another

24
Q

Name some other useful methods in the Thread class

A

T.isAlive();
T.interrupt();
Thread.currentThread().getName();
Thread.currentThread().getID();

25
Q

What is a foreground thread?

A

A foreground thread keeps the application alive until it finishes its task. CLR/JVM cannot exit the application when there is a foreground thread running.
Foreground threads are those which keep running even if the main thread is done with its job and ready to exit or terminate.

26
Q

What is a background thread?

A

A background thread is a thread that runs behind the scenes. For example, a background thread can play music while the application is doing another task.
A background thread is automatically terminated when the application exits even if the thread has not completed its task.

27
Q

True or false:

Every thread has a priority.

A

True. In java, the threads priority is an integer in the range of 1 to 10 where 1 is the lowest. Thread class defines three types of priorities:
o Minimum priority
o Normal priority
o Maximum priority