Sorting data is one of the main components to a process running smoothly and efficiently. There are different ways to sort data. Threading is one way and using I/O is another way to sort. I/O is a major factor in system performance. It places heavy demands on the CPU to execute device-driven code and to schedule processes fairly and efficiently as they block and unblock (Silberschatz, 2010). I/O scheduling request to determine a good order to execute them. This can also be known as rearranging the order of service. Using I/O in a java program can be beneficial, but will slow down the program if not used correctly and bottlenecking will occur.
There are a few ways someone can use I/O within the Java program. The methods are data streams, serialization and the file class. A stream is a sequence of data. The stream can be from many different kinds of sources, including arrays. The stream represents an input source or output destination. A program uses an input stream to read data from a source, one item at a time (Docs.oracle.com, 2017). There are several different kinds of streams to use, depending on the needs of the program and the desired outcome. Java provides a mechanism, called object serialization where an object can be represented as a sequence of bytes that includes the object’s data as well as information about the object’s type and the types of data stored in the object. After a serialized object has been written into a file, it can be read from the file and deserialized that is, the type information and bytes that represent the object and its data can be used to recreate the object in memory (tutorialpoint.com, 2017).
It was my goal to run a program that was concise and accurate and that would run completely without error. I also wanted it to run and complete faster than my threaded version from week 2. I needed the data sorted quickly and correctly. I wanted it to be easy to read and I didn’t want it to loop too many times causing bottlenecking and ultimately the program getting hung up. I took the threaded program from week 2 and chose to use a while loop and the merge sort method to sort the data. In merge sort, the programmer will write the program so that the program will divide into two, sort the data and merge then repeat until all of the data is sorted. I also used the while loop. In this type of loop, as long as the value is true, the loop will continue to repeat until it is false and then it will terminate. In this program, the loop will run until it is false and then will begin sorting and merging the data that remains. In the threaded version, a runnable is used. In this version, the worker threads are used. The worker threads merge and sort also. At the end of the program, it will print to screen how long the program took to successfully run and complete.
Docs.oracle.com. (2017). I/O Streams (The Java™ Tutorials > Essential Classes > Basic I/O). [online] Available at: https://docs.oracle.com/javase/tutorial/essential/io/streams.html [Accessed 9 Oct. 2017].
Silberschatz, A., Galvin, P. B., & Gagne, G. (2010). Operating system concepts with Java (8th ed.). Hoboken, NJ: John Wiley & Sons.
http://www.tutorialspoint.com. (2017). Java Serialization. [online] Available at: https://www.tutorialspoint.com/java/java_serialization.htm [Accessed 9 Oct. 2017].