What should you do?

Domain.com has asked you to create a multi-threaded application, which executes a critical database backup operation on an hourly basis.
You define this operation with the following code:
public void BackupDB () {
//Implementation code
}
You then create a Thread object for the purpose of invoking this method.
You need to ensure that the thread is scheduled for execution before any other thread at runtime.
What should you do?

Domain.com has asked you to create a multi-threaded application, which executes a critical database backup operation on an hourly basis.
You define this operation with the following code:
public void BackupDB () {
//Implementation code
}
You then create a Thread object for the purpose of invoking this method.
You need to ensure that the thread is scheduled for execution before any other thread at runtime.
What should you do?

A.
Use the following code:
Thread th = new Thread (BackupDB);
th.Scheduled = ThreadScheduled.Before;
th.Start ();

B.
Use the following code:
Thread th = new Thread (BackupDB);
th.Priority = ThreadPriority.AboveNormal;
th.Start ();

C.
Use the following code:
Thread th = new Thread (BackupDB);
th.Priority = ThreadPriority.Highest;
th.Start ();

D.
Use the following code:
Thread th = new Thread (BackupDB);
th.Scheduled = ThreadScheduled.First;
th.Start ();

Explanation:
This code instantiates a Thread object that will execute the BackupDB method, specifies the highest priority level for scheduling threads for execution, and starts the thread running. When instantiating a Thread object, you must specify the name of the method it will invoke. The Priority property indicates the relative position of a thread in the wait queue when being scheduled for execution. If two threads arrive in the wait queue at relatively the same time, the higher priority thread will receive the time slice before the other. The Priority property is a ThreadPriority enumeration value, which can be Lowest, BelowNormal, Normal, AboveNormal, and Highest.by default, the Priority property is set to ThreadPriority.Normal.
Incorrect Answers:
A D: You should not use the code fragments that set the Scheduled property with the ThreadSchedule enumeration because no such property or enumeration exists in the System.Threading namespace.
B: You should not use the code that specifies the value ThreadPriority.AboveNormal for the Priority property because this will not schedule the thread for execution before any other thread.



Leave a Reply 0

Your email address will not be published. Required fields are marked *