presenters:
elad laster 208968636
david stern 315556308
subject:
1)In the first part we will create several text files, and count the number of lines created in several different ways:
normal method without the use of threads,method using threads and method using threadpool.
2)In the second part we will create a new "Task" type that consists of an asynchronous operation and priority,
and in addition we will also create a new "ThreadPool" type that will prioritize the type of new tasks we built
- according to their priority.
-
Clone the repository:
git clone https://github.com/EladLaster/OOP_Ex2.git -
Open in any Java IDE.
-
In part 1: Create a number of new text files with a random number of lines and get the total number of lines of the texts by 1 of 3 existing methods/functions present in the class.
In part 2: Bulid a new CustomExecutor and a new task with/without priority, send the task to the new CustomExecutor , submit the task u create in the CustomExecutor and get the result of the task you sent to the program by considering the priority of the task.
-
Enjoy!!!
We want to see that runtimes differ from method to method, and we want to understand which method is more efficient in terms of runtime We can see that by running the ex2 program, it follows that working with Thrades and ThradePool is indeed faster than working without Thrades. This shows that indeed the calculation of lines of text in parallel is better than regular counting. This is obvious because counting rows performed all at once by several objects is faster than counting the lines one at a time. You can also see that working with ThradePool is faster than working with Thrades, because when you create a Thradepool, he already produces a large number of Thrades himself that will be ready to receive tasks, instead of creating Thrades only when the task arrives.
In the following picture we can see the correctness of the claim by create a 5000 files.
the adapter pattern is a software design pattern that allows the interface of an existing class to be used as another interface. It is often used to make existing classes work with others without modifying their source code.
Whenever we want to link an object to a task and there is no real connection between it and the object, we want to build an adapter that will cause an indirect connection between the object and the task that will pass through it. The correlation will make it possible to do this by inserting the values of the given object and adjusting them to the given task.
The main class in which we call the file creation function and the file line count function. running it will show us the total number of lines in the files by one of the method that we defined, and the running times of each method.
The class in which we build the function with which we create new files with a random number of lines. We will also build in it the functions with which we count the total number of lines of the built files - this in one of the 3 ways we have defined: normal method without the use of threads,method using threads and method using threadpool.
-
createTextFiles()
-
getNumOfLines()
-
getNumOfLinesThreads()
-
getNumOfLinesThreadPool()
The class where we create a Thrade that has a name and a counter. In this class we implement the run() function of the Thrade which in the future we will use to count the lines of the files. The function getCounter() will return the number of lines that the specific Thrade found.
-
Thread_ex2()
-
getCounter()
-
run()
The class where we create a ThradePool that has a name and a counter. In this class we implement the coll() function of the ThradePool which in the future we will use to count the lines of the files. The call() function will itself send the number of lines that the ThreadePool found.
-
ThreadP_ex2()
-
call()
In this class we will use an Adapter() that will help us transfer the tasks with a call() function to the tasks with a run() function, this is because later we will want to put them in a priority queue that only accepts tasks that implement a run() function. We will also add a compareTo() function with which the priority queue will compare the tasks.
-
Adapter()
-
compareTo()
The class where we create a CustonExecutor() that has a ThreadPoolExecutore a PriorityBlockingQueue and a arr. In this class, a ThradePool is built with a minimum number of trades - about half the number of processors available for Java Virtual Machine, a ThreadPool is built with a maximum number of available processor tetrads and we subtract 1 from it,and contains within it a queue of priorities. In this class we would like to send the tם the priority queue and execute them with the help of the Thrades. We will also want to keep the highest priority so that we return it in the getCurrentMax() function. At the end, all trades are shut down by the gracefullyTerminate() function.
-
CustomExecutor()
-
exe()
-
submit() - 2 func
-
getCurrentMax()
-
gracefullyTerminate()
The class where we create a Task() that has a Callable and a Type. In this class we will create priority/non-priority tasks that will have their own call() function. We will also build a function that will be able to compare tasks whether they are the same task.
-
_Task()
-
createTask() - 2 func
-
get_priority()
-
call()
-
compareTo()
This class will contain the priorities given to us, between 1 and 10. We can take the priority of any task from this class.
In this class, we will check the functions of the "Ex_1". In the "createTextFiles" function, We would like to see that the number of files we asked a function to build has indeed been created. In the "getNumOfLines" function, We would like to see that the number of rows in the created files does indeed match the number of rows that the function spends (normal method without the use of threads). In the "getNumOfLinesThreads" function, We would like to see that the number of rows in the created files does indeed match the number of rows that the function spends (method using threads). In the "getNumOfLinesThreadPool" function, We would like to see that the number of rows in the created files does indeed match the number of rows that the function spends (method using threadpool).
In this class, we will check the functions of all the file we created. We will introduce new "Tasks" that we have built into the new "CustomExecutor" that we have created, we will check that the results of the tasks are correct and that the "CustomeExecutor" perform the tasks according to the priority - from high to low.




