This essay has been submitted by a student. This is not an example of the work written by professional essay writers.
Reading

Threading and Multi-threading

Pssst… we can write an original essay just for you.

Any subject. Any type of essay. We’ll even meet a 3-hour deadline.

GET YOUR PRICE

writers online

 

Threading and Multi-threading

Threading is a property that allows multiple actions to be taken within the same process. In programming, threading is an important concept that allows multiples instances of a process to be executed in an interleaved manner. Since most operating systems support the threading concept, every developer should take advantage of this aspect. In java programming, threading is included within the language. It is predefined within its pre-installed libraries rather than threading being an operating system concept. Sometimes, threads are considered to be lightweight processes. Threads exhibit the process characteristics such as their local variables, program counters, and they’re on the explicit and implicit stack (Holub, 2010). Threads execute independently just like processes, and they also have their defined concurrent execution paths within a program. However, when dealing with a particular process, threads are less decoupled. Threads share almost every pre-processor state, such as file handlers and computer memory.

The earlier given code demonstrates a non-threading concept. In non-threading, each file data is accessed sequentially. The program reads each element then compares it with the stem data. Each solution obtained is stored in a new array containing values of the final results. The program takes a lot of time to compile, resulting in limited computer resources utilization. However, the program avoids possible issues that result when tasks are executed concurrently.  Non-threading codes are easy to code and implement since they have a simple structure. However, coding a non-threading program may be time-consuming since long codes are written to implement a simple task.

Don't use plagiarised sources.Get your custom essay just from $11/page

Multi-threaded programs, however, allow experienced users to implement complex tasks by simply sub-dividing each program tasks into threads allowing for simultaneous execution of sub-tasks. After modifying the earlier code, it is distinctively clear that multiple threads allow a given program to execute faster. Each thread executes a bit of the program, which are later consolidated to form the final solution. The results obtained after running the two programs show that multi-threaded code takes a shorter time to attain a solution compared to non-threaded code. The time difference obtained is due to the non-uniform utilization of the results.

The main idea behind multi-threading is to execute and run multiple tasks in a concurrent manner. In Java programs, the tasks to be executed are represented as threads having different execution paths. When dealing with multiple threads in Java, it becomes easier since the programmer can define the execution sequence. In the case presented on the non-threading program and multi-threading program, it is evident that multi-threading outcompetes non-threading in several ways.

In the program, the non-threaded program took 1.740986471 seconds to do the sorting while the multi-threaded program took 1.139332902 seconds for reading and sorting the file data.

From the modified program, the performance has been enhanced in terms of development time. The non-threaded program takes a longer time to develop compared to the multi-threaded program. This implies that a programmer can decrease the time taken for a program to build and execute by implementing multi-threading concept in their programs. Multi-threading also allows for simplification and streamlining of program coding (Hawick, 2014). As demonstrated in the program, the sequence at which the sorting process takes place has been simplified through multi-threading. The programmer is not tied to following the primary sequential access to individual elements.

The tasks to be executed occur parallel and simultaneous in their order of execution. The idea of concurrent execution helps the process to execute faster compared to non-threading. It is also evident from the program that, resources such as cache have been properly utilized, having multiple threads running at the same time minimizes the CPU idle time.

On the other hand, when writing the program involving multi-threading it might be complex and difficult, especially for novice programmers. In the program, it is clear to debug and modify the non-threading code compared to a multi-threaded code. There are high chances of deadlocks occurring in the multi-threaded program compared to non-threaded programs; hence the results are unpredictable.

From the figure above, it is clear that the multi-threaded application takes less time compared to the non-threaded application. As discussed earlier, this is due to less development time by multi-threaded programs. In non-threaded application, the process executes sequentially, only a single thread reads data from the file and sorts it in the required manner. In non-threading, the earlier operation must wait until it commits (Sundaresan, Maier, Ramarao, & Stoodley, 2014). On the other hand, the tasks to be executed are divided among several threads which are independent of one another. Therefore, in multi-threading, all the threads act independently.

In the modified code, every individual thread is assigned a particular file to sort as the main thread waits for all the threads commits. Once each thread commits, the main threads combine their results to come up with a sorted file. The program implements the concept of sub-problems gives sub-solutions forming the main solution to an optimization problem. It is also clear that a given process can support several threads executing currently and asynchronously to each other. From the program, the same memory is being addressed by multiple threads at the same time, meaning the same variable data is being read. It can also be concluded that objects are being allocated from the same heap. The information is, therefore, be easily shared among the threads.

The concept demonstrated in the above figure can be applied in a multiprocessor environment. It is tedious to read data sequentially, and sometimes most of the computer resources are un-utilized. In a multiprocessor system, threads can be scheduled to execute in any available processor. From the running concept of a process, the basic unit of execution is a thread which forms the base of scheduling. In a non-threaded application, only one thread is active, executing on a single processor. In a case where a program has multiple threads, it can be scheduled to execute once in different processors (Wabenhorst & Potter, 2018). This improves not only a program performance but also a proper utilization of computer resources. To avoid ‘wait forever’ cases as experienced in non-threading programs, multiple threads are used. Hence, from the practical experience of non-threaded and multi-threaded programs, it is clear that multi-threaded programs are more efficient in terms of complexity and resource utilization.

References

Hawick, K. A. (2014). A Computational Performance Investigation of Java Concurrency using Multi-Threading on Multi-Cored Processors. Software Engineering / 811: Parallel and Distributed Computing and Networks / 816: Artificial Intelligence and Applications. DOI:10.2316/p.2014.811-013

Holub, A. (2010). Object-Oriented Threading Architectures. Taming Java Threads, 251-274. DOI:10.1007/978-1-4302-1129-7_9

Sundaresan, V., Maier, D., Ramarao, P., & Stoodley, M. (2014). Experiences with Multi-threading and Dynamic Class Loading in a Java Just-In-Time Compiler. International Symposium on Code Generation and Optimization (CGO’06). DOI:10.1109/cgo.2006.16

Rabenhorst, A., & Potter, J. (2018). Modeling multi-threading in Java. Proceedings. The technology of Object-Oriented Languages and Systems, TOOLS 25 (Cat. No.97TB100239). DOI:10.1109/tools.1997.681868

  Remember! This is just a sample.

Save time and get your custom paper from our expert writers

 Get started in just 3 minutes
 Sit back relax and leave the writing to us
 Sources and citations are provided
 100% Plagiarism free
error: Content is protected !!
×
Hi, my name is Jenn 👋

In case you can’t find a sample example, our professional writers are ready to help you with writing your own paper. All you need to do is fill out a short form and submit an order

Check Out the Form
Need Help?
Dont be shy to ask