answersLogoWhite

0


Best Answer

Any kind of sequential program is not a good candidate to be threaded. An example

of this is a program that calculates an individual tax return. (2) Another example is a

"shell" program such as the C-shell or Korn shell. Such a program must closely

monitor its own working space such as open files, environment variables, and

current working directory.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Threading is a facility to allow multiple activities to coexist within a single process. Most modern operating systems support threads, and the concept of threads has been around in various forms for many years. Java is the first mainstream programming language to explicitly include threading within the language itself, rather than treating threading as a facility of the underlying operating system.

Threads are sometimes referred to as light weight processes. Like processes, threads are independent, concurrent paths of execution through a program, and each thread has its own stack, its own program counter, and its own local variables. However, threads within a process are less insulated from each other than separate processes are. They share memory, file handles, and other per-process

state.

A process can support multiple threads, which appear to execute simultaneously and asynchronously to each other. Multiple threads within a process share the same memory address space, which means they have access to the same variables and objects, and they allocate objects from the same heap. While this makes it easy for threads to share information with each other, you must take care to ensure that they do not interfere with other

threads in the same process.


The following example uses two threads, one for timing and one to do actual work. The main thread calculates prime numbers using a very straightforward algorithm. Before it starts, it creates and starts a timer thread, which will sleep for ten seconds, and then set a flag that the main thread will check. After ten seconds, the main thread will stop. Note that the shared flag is declared "volatile".

.

/**

* CalculatePrimes -- calculate as many primes as we can in ten seconds

*/

public class CalculatePrimes extends Thread {

public static final int MAX_PRIMES = 1000000;

public static final int TEN_SECONDS = 10000;

public volatile boolean finished = false;

public void run() {

int[] primes = new int[MAX_PRIMES];

int count = 0;

for (int i=2; count

// Check to see if the timer has expired

if (finished) {

break;

}

boolean prime = true;

for (int j=0; j

if (i % primes[j] == 0) {

prime = false;

break;

}

}

if (prime) {

primes[count++] = i;

System.out.println("Found prime: " + i);

}

}

}

public static void main(String[] args) {

CalculatePrimes calculator = new CalculatePrimes();

calculator.start();

try {

Thread.sleep(TEN_SECONDS);
}

catch (InterruptedException e) {

// fall through

}

calculator.finished = true;
}
}




This answer is:
User Avatar

User Avatar

Wiki User

12y ago

A typical example would be to copy 2 big files, say 3 minutes each if doing back to back. (total of 6 minutes minimum)

By using 2 threads, those 2 files maybe copied in 3 minutes (plus a little bit overhead, in theory, just a fraction of a second)

(replace "copy 2 big files" by "downloading 2 MP3, or HD movies, or eBooks"...)

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

Multithreading means that within a program there are different processes (which are called threads) that run simultaneously. As an example, if you use Microsoft Word, there is a foreground process that processes everything you type - that is, while you type letters, the letters appear on the screen. On the other hand, there is a background process that does spell-checking. This is clearly a separate process (thread), and one that has a lower priority; if you type quickly, or paste a lot of text, it can take a while for spelling errors to be marked as such.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

* More than one thread doing I/O on the same device (on an I/O bound task)

* More than one thread using the same data that must be locked

-emman

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Provide to programming example of multithreading that improve performance over a single threaded solutions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Could you give three Programming examples in which multithreading does not provide better performance than a single-threaded solution?

* More than one thread doing I/O on the same device (on an I/O bound task)* More than one thread using the same data that must be locked


What size GM engine has a number 3999289?

454. if it is also stamped with hi performance, it should have threaded studs for components on heads.


Is the District V2 deck threaded?

No deck is threaded it is the headset and the forks that can be threaded or threadless


What is Threaded Flange?

A flange threaded in center used for weld or different types of threaded pipe.


What are the features of structured programming over object oriented programming?

the features of oop are:Emphasis is on data rather than procedure.Programs are divided into what are known as objects.Data structures are designed such that they characterize the objects.Functions that operate on the data of an object are tied together in the data structure.Data is Hidden and cannot be accessed by external functions.Objects may communicate with each other through functions.New data and functions can be easily added whenever necessary.Follows bottom-up approach in program design.others are :· Robust· Multi threaded· Architecture Neutral· High Performance· Distributed· Dynamic


What does multi-core allow?

Multi-tasking! Multiple-core model microprocessors typically perform better in highly-threaded tasks or any applications that require processor multitasking. Keep in mine multi-core processors typically have less per-core performance the higher number of cores they have. This means that, while an 8 core processor does better in highly threaded applications, it will more than likely exhibit lacking performance in single / lightly threaded workloads, such as older programs and most games. Most gamers will tell you that quad or even dual core processors are the best for gaming, due to their lower power requirements, thermal output, and better performance-per-core ratio.


Can i connect threaded stainless nipple to threaded brass valve?

Yes.


Can black steel pipe be threaded?

Black steel depending on schedule can be threaded from 1/8" - 8" Personally I threaded up to 6"


How do you calculate the number of turns in a threaded screw?

Divide the threaded length by the lead length. For single threaded screws the lead is the same as the pitch.


Can You Use Threaded In A Sentence?

"I got my eyebrows threaded for the first time today."


Are outdoor spigots threaded or soldered on?

Outdoor spigots are always threaded and not soldered on.


What barrels will fit a Brass Eagle T Storm Paintball gun?

Any Spyder threaded barrels.