Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

Java Thread

QuestionAnswer
i.Deadlock:There are two threads waiting for each other to complete the task and none get executed. ii.Starvation:Due to high priority process, less priority process gets blocked Which of the above statements are correct? i and ii
Is Synchronized keyword the only reason that most of the times it leads to deadlock condition? TRUE Explanation : Synchronized keyword is the only reason for deadlock situation, which allows only one thread that can access the resource at a given point of time.
Which of the following method suspend the thread for mentioned time duration in argument? Thread.sleep() Explanation : Method gives chance to other Threads for the execution.
Can we detect the deadlock condition? TRUE Explanation : Deadlock situations can be detected by running the executable code on cmd and subsequently collecting the thread dump. If it occurs, the cmd will throw up a message.
Thread.yield() Thread.yield()-When the thread which is in the process after releasing the lock gets a fair chance to occupy the C.P.U. and can get time to complete its execution till the original thread again gets the control over the C.P.U.
Can we completely avoid deadlock in Java? FALSE Explanation : We cannot completely avoid deadlock but can follow these measures to them. Avoid Nested Locks - avoid giving locks to multiple threads. Avoid Unnecessary Locks - lock is for important thread not for unnecessary threads.
Thread.join Using Thread Join- use Thread.join with a maximum time that a thread will take to avoid a situation where a thread waiting for other thread to release.
Which of the following is said to occur when a particular thread does not get access to the object or the resource which leads to an increase in waiting and execution time? Starvation Explanation : In Starvation, Threads will wait for each other. But waiting time is not infinite after some interval of time, waiting thread gets the resources whatever is required to execute thread run() method.
A _______ is a low priority thread which always runs in the background. Daemon thread
Can we create threads in Java? TRUE Explanation : We can create threads in two ways. By implementing Runnable interface and By extending Thread class
Which method is used to return a boolean value to check if daemon thread is present or not? isDaemon()
What are the methods related to the thread priority. public final int getPriority():java.lang.Thread.getPriority() method returns priority of the given thread public final void setPriority(int newPriority): java.lang.Thread.setPriority() method updates or assign priority of the thread to newPriority
Is there any class in Java which helps us to create a thread? Yes, there is a Thread class in java helps us to create a thread. Create a class and extend that class by Thread class. Then, the created class will act as thread in Java. After extending Thread class, the class should override the run method.
Thread start() After creating object for the class, we can use start() method to run the method. When the method gets started by calling start() method, a new thread is created and starts executing it. By this time, the main thread will continue the remaining part.
If the value of the parameter "newPriority" of the method "getPriority()" goes out of the range (1 to 10), then the method throws _______. IllegalArgumentException
public class ThreadPriority extends Thread { public static void main(String argvs[]) { _____________________.setPriority(6); ThreadPriority th1 = new ThreadPriority(); } } Thread.currentThread()
Which of the following is the process of executing one or more threads simultaneously? Thread is termed as a lightweight process. A process is divided into parts, each part called Thread. Multithreading is the process of executing one or more threads simultaneously. Threads will share a common memory and the execution will also be faster.
Which scheduling algorithm is supported by the JVM to serve the thread with the highest priority first, since all Java threads have a priority. Fixed-priority pre-emptive scheduling
A _______ is a self-contained sequence of instructions that can execute in parallel with other threads that are part of the same root process. thread
Which of the following is TRUE. All of the above A process is a part of the program in execution A core can have upto 2 threads and we can utilize the 2 threads based on the process A thread is a lightweight process
Which of the following is/are correct statements. All of the above A processor is madeup of multiple cores A core is physical component where threads are virtual component Thread is a virtual division of cores
We can pass lambda expression while creating the object of Thread class instead of creating lambda expression of Runnable interface. true
Which method is used to find the state of the thread? getState()
Which method is used to check whether the thread is terminated or not? isAlive()
Which method is used to allow the thread to complete its execution while another thread is waiting? join()
Which method is used to name a thread? setName()
Which method is used to wake a thread from waiting state? notify()
When synchronized keyword is used before the method, the method becomes thread safe. true
All the methods by default is synchronized. false
Which method is used to pause the thread for require time? sleep()
Which method is used to move the current thread to the waiting state. wait()
Which method is used for inter communication between the threads? wait()
What is multi-threading?
In what ways can you create a thread? run(), start()?
List the methods in the Thread class and Runnable interface
Explain the lifecycle of the thread?
What is deadlock?
What is the synchronized keyword?
Which of the following are virtual machine states of a thread? Runnable Blocked Terminated Waiting
Which of the following are created on a per-thread basis? JVM stack Native Stack PC Register
Thread dumps are snapshots of the current state of all threads that are part of the process true
The run() method comes from the Thread class false It comes from the Runnable functional interface
Each thread gets its own stack and heap false Threads receive their own stack, not their own heap
Threads can be created by extending the Runnable class false Runnable is an interface, not a class
Which of the following Thread methods is used to wait for the thread to finish execution? Thread.join();
What is a thread? A representation of a path of execution, allowing for concurrent processing
Threads can be created by passing a Runnable into the constructor of Runnable: new Runnable(Thread)
Which of the following is a Thread state in Java? Blocked Waiting New
Which one of the following is a valid class declaration? class example implements Serializable, Runnable
volatile related to the visibility of variables that are modified by multiple threads at the time of concurrent programming.
Created by: wahoo99
Popular Computers sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards