Algorithm Programming 1 89-210 Exercise 3 Bar-Ilan University 2007-2008 תשס"ח by Moshe Fresko.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Applications of Synchronization Coverage A.Bron,E.Farchi, Y.Magid,Y.Nir,S.Ur Tehila Mayzels 1.
Computer Programming Lab(7).
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Algorithm Programming Exercise 2 Bar-Ilan University תשס"ח by Moshe Fresko.
Algorithm Programming Concurrent Programming in Java Bar-Ilan University תשס"ח Moshe Fresko.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
Algorithm Programming Some Topics in Compression
Algorithm Programming Exercise 4 Bar-Ilan University תשס"ז by Moshe Fresko.
Algorithm Programming Exercise 1 Bar-Ilan University תשס"ח by Moshe Fresko.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Thread Pools. 2 What’s A Thread Pool? A programming technique which we will use. A collection of threads that are created once (e.g. when server starts).
11 Chapter 5 METHODS. 22 INTRODUCTION TO METHODS A method is a named block of statements that performs a specific task. Other languages use the terms.
Threads in Java1 Concurrency Synchronizing threads, thread pools, etc.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
1 COMPSCI 110 Operating Systems Who - Introductions How - Policies and Administrative Details Why - Objectives and Expectations What - Our Topic: Operating.
Nachos Phase 1 Code -Hints and Comments
CSCI 171 Presentation 1. Computer Software System Software –Operating systems –Utility programs –Language compilers Application Software.
Overview of Threading with the.NET Framework  Wallace B. McClure  Scalable Development, Inc. Scalable Development, Inc. Building systems today that perform.
Threads some important concepts Simon Lynch
Compiled Matlab on Condor: a recipe 30 th October 2007 Clare Giacomantonio.
Programming With C.
A SSIGNMENT 1: S IMPLE A RRAY IN J AVA Create 2 Class Accessories Class: MyArray.java Implement an array in Class MyArray Implement a series method to.
Exceptions. Exception Abnormal event occurring during program execution Examples –Manipulate nonexistent files FileReader in = new FileReader("mumbers.txt“);
Comnet.technion.ac.il/~cn23s00 Computer Networks Laborator y Technion Israel Institute of Technology BlueTooth High-Level Simulator A Base Platform For.
Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result.
How to start Visual Studio 2008 or 2010 (command-line program)
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
Chapter 2: Java Fundamentals
1 (Worker Queues) cs What is a Thread Pool? A collection of threads that are created once (e.g. when a server starts) That is, no need to create.
Java Classes. Consider this simplistic class public class ProjInfo {ProjInfo() {System.out.println("This program computes factorial of number"); System.out.println("passed.
Dynamic Architectures (Component Reconfiguration) with Fractal.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
Concurrent Programming and Threads Threads Blocking a User Interface.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Reusing threads.
1 Project 5: Printing Address Labels. 2 Assignment Write a Windows forms program to display and print a set of address labels. Input from a csv file.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
CSE 451: Operating Systems Section 3: Project 0 recap, Project 1.
Operating Systems Process Creation
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
Module 8 Enhancing User Interface Responsiveness.
A brief introduction to javadoc and doxygen. What’s in a program file? 1. Comments 2. Code.
Threads. Objectives You must be able to answer the following questions –What code does a thread execute? –What states can a thread be in? –How does a.
1 OS Review Processes and Threads Chi Zhang
Exceptions. Exception  Abnormal event occurring during program execution  Examples Manipulate nonexistent files FileReader in = new FileReader("mumbers.txt“);
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Documentation Javadocs. Design/Documentation An essential ingredient of good Object Oriented programming is known as design by contract. This means that.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
1 Java Programming Java Programming II Concurrent Programming: Threads ( I)
CS 112 Introduction to Programming Loop Patterns: break; Fencepost Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone:
Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a.
…in java DThread Pools x. Thread Pools: Why? Source code updates – copy/paste of run/runnable method for each thread is exhausting There is overhead to.
Prepared by Oussama Jebbar
Thread Pools (Worker Queues) cs
Introduction to programming in java
Thread Pools (Worker Queues) cs
Chapter 6 Queue.
Lecture Note Set 1 Thursday 12-May-05
Introduction to javadoc
L3. Necessary Java Programming Techniques
L3. Necessary Java Programming Techniques
Multithreaded Programming
Chapter 6 Queue.
Chapter 6 Queue.
Introduction to javadoc
Threads in Java James Brucker.
Exceptions.
Methods/Functions.
Exceptions.
Presentation transcript:

Algorithm Programming Exercise 3 Bar-Ilan University תשס"ח by Moshe Fresko

Exercise 3 – Thread Pool Implementation And Usage  Motivation: Re-use of existing threads  Because thread creation is an expensive task Control the number of threads running concurrently  Not going into starvation 1. Write an interface Job in file Job.java that will define a new job that can be executed in the Thread Pool. Remember the “ Command ” design pattern. interface Job { void execute() ;// Executes the required process void stop() ;// Stops the process in the middle String getDescription(); // A description about the type of the job }

Exercise 3 – Thread Pool Implementation And Usage 2. Write a general purpose class ThreadPool in file ThreadPool.java that will have the following functionality. class ThreadPool { // Constructor will get the maximum number of threads // that can run concurrently public ThreadPool(int numOfMaxThreads) { … } // Method for adding a new Job for execution. It returns immediately. public void add(Job j) { … } // Method for getting information on the Thread Pool ’ s State public ThreadPoolState getState() { … } // Method for getting statistics for that Thread Pool public ThreadPoolStatistics getStatistics() { … } // Method for stopping the whole process. void stop() { … } }

Exercise 3 – Thread Pool ThreadPoolState and ThreadPoolStatistics  Information on ThreadPool will be get in structures that will be defined by these definitions. interface ThreadPoolState { int getNumberOfThreads() ; String[] getDescriptionsOfRunningJobs() ; String[] getDescriptionsOfWaitingJobs() ; } interface ThreadPoolStatistics { int getNumberOfExecutedJobs() ;// The jobs that their execution is finished int getNumberOfJobsLeftTheQueue() ; // This must be >= the number of executed jobs int getAverageExecutionTime() ; // In milliseconds. For the executed jobs. int getAverageWaitingTime() ; // In milliseconds. For the jobs that left the queue. }  These structures will be filled and returned by the functions getState() and getStatistics() functions. The returned value will be static (will not change). A new value will be returned for each call to those functions.

Exercise 3 – Thread Pool Implementation And Usage 3. Write an application Ex3 with a main function, that will do the following. It will prompt for a user input, will run the given command and will return again to prompt. The following are the available commands.  HELP : Will display a general help how to use the program.  COMPRESS FileName CompressedFileName DECOMPRESS CompressedFileName FileName  STATE : Will print the list of running/waiting jobs.  STATISTICS : Will print the information from getStatistics()  EXIT : Stops the ThreadPool and exits from the program.

Exercise 3 – Thread Pool Implementation And Usage 4. There will be a single Thread Pool object in the program. 5. Command description:  COMPRESS Algorithm FileName CompressedFileName will create 1 job and put that into the Thread Pool. The job will compress the given file to create the given CompressedFile. For example: COMPRESS A.txt CompressedA.bin will run one job in the thread pool so that the File A.txt will be compressed according to LZW algorithm.  DECOMPRESS CompressedFile OutputFileName This fill open the file and will create the original file  For Example: DECOMPRESS CompressedA.bin B.txt will run one job in the thread pool. After the job was run and finished, B.txt must be created with the same content as previous A.txt.

Exercise 3 – Thread Pool Implementation And Usage  Some points: 1. Do not forget to synchronize where necessary. Do not over-synchronize in unnecessary places. 2. ThreadPool class is a general utility class, and it will not have any code connected to Compression, LZW or other special things. You can define specific things in Ex3.java or in other files. 3. The getDescription() for our specific jobs might be the following: 1. “ Job for Compressing ‘ File1 ’ into ‘ File2 ’ with LZW algorithm. ” 2. “ Job for DeCompressing ‘ File1 ’ into ‘ File2 ’ with LZW algorithm. ”

Exercise 3 Thread-Pool  Important: You submit via submitex.  Course number:  Exercise: ex3  Deliver all the necessary files. It must compile/work under Java 1.4/1.5/1.6. You can try it on the Unix environment (on Sunshine). Do not write debugging information to the console or any other place. Write enough comments. Write wherever you think there is a need for the understanding of the code. Write your code according to the OOP principles. Everybody must do it alone.  Deadline: 15 Jan 2008