answersLogoWhite

0


Best Answer

A thread that is continuously executing has an infinite loop. To terminate that thread you must break that loop by providing a suitable terminating condition. If the thread is a "worker" thread, the main thread should signal all worker threads to terminate when the main thread terminates. The main thread should remain active until all worker threads have successfully terminated.

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you terminate a thread which is continuously executing?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What happens to child thread when you delete main thread during run-time?

In Java, if the main thread somehow exits then all other threads will stop executing. This generally does not happen, as the main thread will wait for all child threads to terminate before the main thread itself finishes. Interrupting this process is hard to do short of an un-handled exception or a call to System.exit. If the child thread is also a daemon thread, then the child thread will continue to execute. If the child thread is a normal thread then, the moment System.exit is called, the child thread also terminates If you call the join() method from the child thread, then the main thread will wait until the child is over before executing the System.exit


If process stop its execution will thread also stop or it will continue to run?

Processes do not execute, it is the threads within a process that actually execute. All processes have at least one thread of execution, the main thread. If the main thread falls from scope, the process ends, taking all threads with it. This can lead to undefined behaviour if the threads are not terminated gracefully from within the main thread before it falls from scope.


Distinguish the terms Program Process and Threads?

A program is an executable. A process is an executable that has been loaded into working memory and is currently executing the program. A thread is a thread of execution within a process. Every process has at least one thread, but threads can spawn additional threads as required to allow concurrent operations to be performed near-simultaneously.


Life cycle of thread in java?

# New state - After the creations of Thread instance the thread is in this state but before the start() method invocation. At this point, the thread is considered not alive.# Runnable (Ready-to-run) state - A thread start its life from Runnable state. A thread first enters runnable state after the invoking of start() method but a thread can return to this state after either running, waiting, sleeping or coming back from blocked state also. On this state a thread is waiting for a turn on processor. # Running state - A thread is in running state that means the thread is currently executing. There are several ways to enter in Runnable state but there is only one way to enter in Running state: the scheduler select a thread from runnable pool.# Dead state - A thread can be considered dead when its run() method completes. If any thread comes on this state that means it cannot ever run again. # Blocked - A thread can enter in this state because of waiting the resources that are hold by another thread.


What is the difference between a Parent Process and Foreground Process?

A parent process is a process that has spawned one or more child processes such that it takes "ownership" of those processes. A foreground process typically means a process that has a user-interface as opposed to a background process which typically does not. Most background processes are services while most foreground processes are applications. It's important to note that the term "process" has a specific meaning in a multi-processing environment. A process is a computer program that has one or more threads of execution. A thread is the machine-level representation of a task and a process may instantiate as many tasks as are required (hardware permitting). All tasks share the same memory space as the process itself, however each task has its own stack for local storage, as well as to enable the thread's function call-and-return mechanism in addition to thread-local exception handling. Every process must have at least one thread of execution typically referred to as the main thread because that is the thread that executes the program's global main function (the entry point of the application) and subsequently instantiates any additional threads required by the main thread. The additional threads are usually called worker threads and any thread can instantiate its own worker threads. Unlike parent/child processes, thread's cannot "own" other threads; the threads are owned by the process. However, it is possible for worker threads to be controlled by other threads in the same process, so in that sense the controlling thread can be said to be a parent thread. When the main function returns, the main thread terminates, however any active threads within the process will continue executing, thus keeping the process "alive". In many cases this would be undesirable particularly if those threads attempt to access shared memory that is released by the main thread. So although there is no notion of ownership amongst threads, any controlling thread that must terminate before its workers have completed their tasks should signal its workers to terminate and then wait for them to terminate before terminating itself. Threads of execution within a process execute concurrently. All this means is that the operating system's task scheduler gives each thread a time-slice of the CPU to do some work, before saving the thread's state and moving onto the next thread (which may belong to another process entirely). Task-switching is so rapid that it can appear as though all threads are executing simultaneously, however that is only physically possible when the CPU has 2 or more cores available. Only one thread may execute upon any single core at any given moment. Multiple threads are typically used to maintain responsiveness. In a GUI environment, a time-consuming task would take up the entire time-slice of a process so it won't be able to respond to any messages on the message queue unless the task specifically checks the queue periodically. However, by using a worker thread to carry out the task, the controlling thread can remain responsive to messages. The message queue can also be used by threads to signal other threads, thus a controlling thread can respond to periodic progress reports from its worker threads if required. In this sense it can be said that the worker threads are background tasks, while the controlling thread is the foreground task.

Related questions

What happens to child thread when you delete main thread during run-time?

In Java, if the main thread somehow exits then all other threads will stop executing. This generally does not happen, as the main thread will wait for all child threads to terminate before the main thread itself finishes. Interrupting this process is hard to do short of an un-handled exception or a call to System.exit. If the child thread is also a daemon thread, then the child thread will continue to execute. If the child thread is a normal thread then, the moment System.exit is called, the child thread also terminates If you call the join() method from the child thread, then the main thread will wait until the child is over before executing the System.exit


Which cannot directly cause a thread to stop executing?

notify()


If a process terminates will its thread also terminate?

yes, because if process is terminated then its related thread has no work. After completion of process the kernel generates a thread that will cancelled the thread in order to save the time and memory of CPU.


If a process terminates will its thread also terminates?

Yes, the thread will also terminate if the process it is running in terminates. The thread is dependent upon the processes it is running. If the processes die the thread dies.


What are the threads called?

tl;dr: They're called threads because thread is an apt metaphor. When you start a thread, you rely on the operating system to allocate processing time so that your thread can execute. While your thread is executing, the processor (or core) is placing all of its attention on your thread.


What are the methods to forcibly terminate a thread?

To end a thread within the thread's own code you can also simply return from the thread function or method. However if you want to terminate a thread from code which is running outside of the thread's own flow you must typically code a mechanism of your own to do this. A simple way to do this is to have the threaded code check a shared signal variable every so often, if the variable is signaled - then the threaded code exits and the thread dies. Terminating a process (in C with say exit(..) ) will typically force the closing of any associated threads.


Why do water faucets sometime turn continuously?

The thread on the tap has broken and needs to be replaced.


What is main thread in java program?

the main thread is the first thread that creates when the JVM starts executing your program. All subsequent threads that you may create in your program would be child threads to the main thread. It is important to note that if the main thread exits, all other threads that were spawned by it will also get killed.


What is multi thread operating system?

Basically a thread means a process which CPU is executing at particular time, if you want to run many processes (applications) in the same time, you need to have multithread OS.


What is ment by thread interaction in java?

Two threads can interact with one another using the wait and notify methods. If one thread wants another thread to wait until it completes, it can use the wait method. similarly if it wants the other threads to know that it is done executing, it can use the notify or notifyall methods


How do you ping continuously?

, the Ping command provides you with a parameter that configures the command to continuously ping the target device until you manually terminate the operation:Ping -t xxx.xxx.xxx.xxxIn this command, xxx.xxx.xxx.xxx is the IP address of the target device.To temporarily interrupt a continuous Ping operation and display the statistics, press [Ctrl][Break]. To completely terminate a Ping operation, press [Ctrl]C.


If process stop its execution will thread also stop or it will continue to run?

Processes do not execute, it is the threads within a process that actually execute. All processes have at least one thread of execution, the main thread. If the main thread falls from scope, the process ends, taking all threads with it. This can lead to undefined behaviour if the threads are not terminated gracefully from within the main thread before it falls from scope.