(Spring 2019) Software configuration: Rain classroom papers (Chapter 10)

2 minute multiple choice question 1

The following __ is concurrency phenomenon in a computer system?

A App on a mobile phone network to access cloud data through 5G
B quad-core CPU, multi-channel program execution
Java programs using C Observer design pattern, wherein execution of Subject and Observer classes Class
D million people while landing 12306 buy train tickets during Spring Festival
E use JVM parameters -XX: + UseConcMarkSweepGC start of the program, run by GC
F two threads within the same Java program, sharing a mutable Java object

The correct answer: ABDEF

2 multiple choice questions 2 points

On process and thread argument, is not correct _

A not shared among the plurality of memory process, the memory can be shared between a plurality of thread
a B CPU core and only a single process runs at a specific point in time, but may be performed in parallel a plurality of thread
the App 5G phone via the C resource network to access the cloud server, running on the phone and server are different thread rather different process
D a process can contain multiple thread, a thread can only run in a process where

The correct answer: BC

3 multiple choice questions 2 points

On how to create a thread to say, it is not correct __

When A subclass A from Thread class, create a thread (new A ()). Start ()
Class B A implement Runnable, and achieve its run () method, a thread is created (new Thread (new A () )) .run ()
C new new the Thread (new new the Runnable () {
public void RUN () {...};
}). Start ();
D new new the Thread (new new the Runnable () {
public void RUN () {...};
}). run ();

The correct answer: BD

Multiple choice question 4 2 points

About time slicing, interleaving and race condition argument is correct __

A Time slicing is determined by the OS, but the programmer can control certain limited code
B correctly if the results of a program or not depends on time slicing, it means that the execution of the program generated for condition Condition Race
C interleaving execution of the program the basic unit is a Java line of code
multiple times D with a concurrent program in the time slicing may be completely different, so the bug is difficult to reproduce the image of such a bug become Bohrbugs

The correct answer: AB

5 multiple choice questions 2 points

About Java Thread the sleep () and interrupt (), it is not correct __

A If the thread run () tag comprising Thread.sleep (100), the thread stops executing means 100ms, CPU to other threads / processes using
thread B t1 has code t1.interrupt (), after executing the meaning t1 is stopped after the statement, will not get slicing Time
C t1 thread in another thread to sleep can capture sent to the interrupt signal and throw InterruptedException exception was generated during ()
D thread if caught throws InterruptedException exception, the automatic termination of execution

The correct answer: BD
Analysis: During normal operation, even if the interrupt signal is received, do not care.
In sleep () when detecting whether other people received interrupt signal. If so, an exception is thrown.
After entering the exception handling, thread really terminated.

6 multiple-choice questions 2 points

Thread t = new Thread(new Runnable(){
public void run(){
try{
print(“a”);

Thread.sleep(200);
}catch(InterruptedException e){
print(“b”);
}
print(“c”);
};});

t.start ();
...
; t.interrupt ()
certain of the main () the code shown above, may be performed after the output is ___
A ab &
B AC
C BC
D ABC

The correct answer: BD

Fill in the blank 7 3 points

If you want the thread t perform again after the end of the implementation of the other threads that allow other threads to pause, you need to call t. Fill in the blanks 1 ;
the correct answer: join ()
for "to detect whether the current thread other threads receive incoming interrupt signals" thread static thread method. fill in the blank 2
interrupted the ()
() method has the following code in the thread class is run, a thread of execution to terminate receiving an interrupt signal if desired, the position of the statement should be TODO [fill in the blank. 3]
return;
the try {
...
the Thread.sleep (1000);
...
} the catch (InterruptedException E) {
the TODO;
}
correct answer:
the Join; interrupted; return

10-2 thread-safe

2 minute multiple choice question 1

About ADT ThreadSafe the following statement, is not correct __

A Any ADT released must Safe to do the Thread
B no matter how time slicing and interleaving, RI a thread-safe object to ADT is always true
C on a different machine, procedures for the implementation of the ADT on different OS , RI is not a violation of the situation should arise
D immutable any of ADT are threadsafe of
E ThreadSafe or not do, only to achieve its own internal rep with ADT and related internal methods, and whether the client should follow certain conditions relating to

The correct answer: AD
Answer Analysis:

Option A: Not necessarily, for example, where there are a lot of JDK in multithreaded programs in unsafe ADT, such as List, Iterator. This situation can be clearly written on spec in. However, it is preferable to provide corresponding thereto threadsafe ADT's.

B, C, E options are an important expression of constraint ThreadSafe: threadsafe and run your program under what hardware and software environment, whom by the procedure call, it does not matter.

D:beneficent mutation

2 multiple choice questions 2 points

About Strategy 1: Confinement to say, is not correct __

Do not share mutable data objects between A multi-threading
within each thread B should not use mutable data objects of
C variable as long as the ADT's rep in the presence of static type, the ADT in any multi-threaded scenarios can not be done threadafe
D as long as the ADT the rep in the presence of mutable types of variables, the ADT in any multi-threaded scenarios can not be done threadsafe

The correct answer: BCD
Answer Analysis:

Option A is the core idea of ​​the strategy

Option B: internal thread of course use mutable objects, as long as they are limited to use only in this thread (not shared with other threads, confined in its own thread stack), that is in line with the policy

Option C: If the static attribute is immutable and does not exist (or the safety of these mutable attributes ensured by other policy) property other mutable, then you can do it thread-safe

Limit Option D: See explanation C options

3 multiple choice questions 2 points

For Strategy 2: Immutability, not correct to say that __

A strategy that is thought: when sharing data among multiple threads, immutable and immutable data type references, in order to avoid the race condition between the multi-thread
B If multiple threads share data type is mutable, by the thread disable mutator methods to achieve its THREADSAFE
C if rep ADT's All properties are final, then it can be done in any multi-threaded threadafe scene
attribute D if there is public rep ADT's type, then it can not be ensured do threadsafe

The correct answer: BC
Answer Analysis:
B Options: threadsafe client can not ask for anything, you must be a responsibility of ADT

Option C: light final is not enough, pointing to the object had to be immutable's. Otherwise, you can generate multi-threaded race condition to modify its value

Option D: public property meant rep exposure, that thread can modify their rep, it is possible race condition. The policy requires that all variables are private and final.

Multiple choice question 4 2 points

For Strategy 3: Using Threadsafe Data Types strategy is not correct __

A If you must use a mutable data types to share data between multiple threads, use thread-safe data type
B if used in collections rep ADT's best to use synchronizedMap / ... List Syn / Syn ... NET
C if do B option to say, the ADT in any multi-threaded scenarios can be done tHREADSAFE
D even on a thread-safe collection classes, use the iterator is unsafe

The correct answer: C

5 1 minute multiple choice questions

public class P{
private static P p = null;
// invariant: only one P object
// should be created

public static P getInstance() {
  1.  if(p == null) {
    
  2.  	p = new P();
     }
    
  3.  return P;
    
    }

    }

There are two threads that run () method are calling getInstance ().
If the thread is executing statement 1 1, 2 thread 3 is executing the statement, then we would produce race between two threads and lead to invariant is violated?
YES A
B NO

The correct answer: A

6 multiple-choice questions 2 points

T = new new String String public ();
Private new new List OL = the ArrayList <> ();
Private LS = the Collections.synchronizedList Final List (OL);
an ADT of Rep as shown above, the ADT is used when a scene multithreaded the threadsafe, the following statement is not correct ___

A t thread safety risk does not exist, because it is of type String is immutable in
the presence of thread safety risks B ol, as List <> not thread-safe data type
thread safety risks C ls does not exist, because it uses synchronizedList made package
D ls there is thread-safe risk, there may be calls to multiple methods of ls in a method of the ADT, it may produce race

The correct answer: AC

7 multiple choice questions 2 points

Thread 1:

if ( ! lst.isEmpty()) {
	String s = lst.get(0);
	...
}
线程2:
if ( lst.size() >=1) {
	lst.remove(0);
	...
}

Lst wherein the object is using the Collections.synchronizedList List () is obtained, the following is correct:

Since lst A data type is a thread-safe, so that two threads race condition does not exist
race condition between the thread B isEmpty 1 () and 2 thread size () causes the unexpected consequences of
C thread isEmpty 1 () and remove the thread 2 () produces race condition caused by the unexpected consequences
D threads get 1 of () and remove the thread 2 () produces race condition caused by the unexpected consequences

The correct answer: CD

Published 113 original articles · won praise 1067 · Views 170,000 +

Guess you like

Origin blog.csdn.net/JAck_chen0309/article/details/105022501