/** * Created Aug 19, 2012 */ package com.roguelogic.util;

Size: px
Start display at page:

Download "/** * Created Aug 19, 2012 */ package com.roguelogic.util;"

Transcription

1 / Copyright 2012 Robert C. Ilardi Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. / / Created Aug 19, 2012 / package com.roguelogic.util; import java.io.file; import java.io.fileinputstream; import java.io.ioexception; import java.util.properties; Robert C. Ilardi This is a Sample Class for a Standalone Daemon Process. Implementations that use this template may be run from a scheduler such as Cron or Autosys or as Manual Utility Processes using the UNIX Command NOHUP.

2 IMPORTANT: This Java Process is intended to be ran with NOHUP. I have released this code under the Apache 2.0 Open Source License. Please feel free to use this as a template for your own Daemons or Utility Process Implementations. Finally, as you will notice I used STDOUT AND STDERR for all logging. This is for simplicity of the template. You can use Log4J or Java Logging or any other log library you prefer. In my professional experience, I also include an Exception or "Throwable" er mechanism so that our development team receives all exceptions from any process even front-ends in real time. / public class DoNothingStandaloneDaemon { / I personally like having a single property file for the configuration of all my batch jobs and utilities. In my professional projects, I actually have a more complex method of properties management, where all properties are stored in a database table, and I have something called a Resource Bundle and Resource Helper facility to manage it. My blog at EnterpriseProgrammer.com has more information on properties and connection management using this concept. However for demonstration purposes I am using a simple Properties object to manage all configuration data for the Standalone Process Template. Feel free to replace this field with a more advanced configuration management mechanism that means your needs. /

3 private Properties appprops; / This flag ensures that the Cleanup method only runs once. This is because I wanted to have a shutdown hook, in case the process receives an interrupt signal and in the main method, I explicitly call cleanup() from the finally block. Technically the shutdown hook based on my implementation is only a backup so it actually will never run unless there's a situation like an interrupt signal. / private boolean rancleanup = false; / If this variable is set to true, any exception caused in the cleanup routine will cause the entire process to exit non-zero. However in my professional experience, we usually just want to log these exceptions, perhaps even them to the team for investigation later, and allow the process to exit ZERO, so that the batch job scheduler can continue onto the next job, especially is the real execution is completed. / private boolean treatcleanupexceptionsasfatal = false; / We need a object monitor to control the background thread used to run the execution loop. / private Object loopcontrollock = new Object(); / A flag with tells the start and stop methods if the execution loop thread

4 has started or not. / private boolean loopstarted; / This flag tells the start, stop, and waitwhileexecution methods if the process loop is running. It is also used to STOP the process loop from running. / private boolean runprocessing = false; / This parameter needs to be set in order for the process loop to sleep a certain number of seconds between each consecutive call to the actual processing logic method. / private int processloopsleepsecs; / This field is used as a counter for the number of processing loop iterations. For debugging, logging, and even custom logic implementation purposes, this is a nice piece of information to have. / private long loopiterationcnt; / This is the file path for the stop file watcher to watch. When the stop file watcher thread finds the stop file at this location, it will gracefully shutdown the daemon process. / private String stopfilepath;

5 / We don't want to spend too many cycles watching for a stop file especially since a daemon process normally runs for hours, days, or even weeks, so we have a separate sleep seconds variable to control the interval between file system checks. / private int stopfilesleepsecs; / This flag tells the start, stop file watcher methods if the file watcher loop is running. / private boolean runstopfilewatcher; / We need a object monitor to control the background thread used to run the stop file watcher loop. / private Object stopfilewatchercontrollock = new Object(); / A flag with tells the start and stop methods if the stop file watcher loop thread has started or not. / private boolean stopfilewarcherloopstarted; / I'm not really using the constructor here. I purpose more explicit init methods. It's a good practice especially if you work with a lot of reflection, however feel free to add some base initialization here if you

6 prefer. / public DoNothingStandaloneDaemon() { // Start public methods that shouldn't be customized by the user // > / The init method wraps two user customizable methods: 1. readproperties(); - Use this to add reads from the appprops object. 2. customprocessinit() - Use this to customize your process before the execution logic runs. As stated previously, so not touch these methods, they are simple wrappers around the methods you should customize instead and provide what in my professional experience are good log messages for batch jobs or utilities to print out, such as the execution timing information. This is especially useful for long running jobs. You can eventually take average over the course of many runs of the batch job, and then you will know when your batch job is behaving badly, when it's taking too long to finish execution. / public synchronized void init() { long start, end, total; System.out.println("Initialization at: " + GetTimeStamp()); start = System.currentTimeMillis(); readproperties(); // Hook to the user's read properties method. customprocessinit(); // Hook to the user's custom process init method! end = System.currentTimeMillis(); total = end - start;

7 System.out.println("Initialization Completed at: " + GetTimeStamp()); System.out.println("Total Init Execution Time: " + CompactHumanReadableTimeWithMs(total)); / Because we aren't using a more advanced mechanism for properties management, I have included this method to allow the main() method to set the path to the main properties file used by the batch jobs. In my professional versions of this template, this method is embedded in the init() method which basically will initialize the Resource Helper component and obtain the properties from the configuration tables instead. Again you shouldn't touch this method's implementation, instead use readproperties() to customize what you do with the properties after the properties load. / public void loadproperties(string apppropspath) throws IOException { FileInputStream fis = null; try { fis = new FileInputStream(appPropsPath); appprops = new Properties(); appprops.load(fis); // End try block finally { if (fis!= null) { try { fis.close();

8 catch (Exception e) { / This method sets the number of seconds the process loop will sleep between each call to the logic processing processloopsleepsecs / public void setprocessloopsleepsecond(int processloopsleepsecs) { this.processloopsleepsecs = processloopsleepsecs; / This method sets the number of seconds between each stop file check by the stop file stopfilesleepsecs / public void setstopfilewatchersleepseconds(int stopfilesleepsecs) { this.stopfilesleepsecs = stopfilesleepsecs; / This method sets the file for the stop file watcher to loop stopfilepath /

9 public void setstopfilepath(string stopfilepath) { this.stopfilepath = stopfilepath; / This method performs the cleanup of any JDBC connections, files, sockets, and other resources that your execution process or your initialization process may have opened or created. Once again do not touch this method directly, instead put your cleanup code in the customprocesscleanup() method. This method is called automatically in the last finally block of the main method, and if there's an interrupt signal or other fatal issue where somehow the finally block didn't get called the Runtime shutdown hook will invoke this method on Exception / public synchronized void cleanup() throws Exception { long start, end, total; // This prevents cleanup from running more than onces. if (rancleanup) { return; try { System.out.println("Starting Cleanup at: " + GetTimeStamp()); start = System.currentTimeMillis();

10 stopstopfilewatcher(); // Make sure the stop file watcher is stopped! stopprocessingloop(); // Make sure the processing loop is stopped! customprocesscleanup(); // Hook to the users Process Cleanup Method end = System.currentTimeMillis(); total = end - start; System.out.println("Cleanup Completed at: " + GetTimeStamp()); System.out.println("Total Cleanup Execution Time: " + CompactHumanReadableTimeWithMs(total)); rancleanup = true; // End try block catch (Exception e) { / It is in my experience that the Operating System will cleanup anything we have "forgotten" to clean up. Therefore I do not want to waste my production support team members time at 3AM in the morning to handle "why did a database connection not close" It will close eventually, since it is just a socket, and even if it doesn't we'll catch this in other jobs which may fail due to the database running out of connections. However I usually have these exceptions ed to our development team for investigation the next day. For demo purposes I did not include my Exception/Stacktrace ing utility, however I encourage you to add your own. If you really need the process to exit non-zero because of the cleanup

11 failing, set the treatcleanupexceptionsasfatal to true. / e.printstacktrace(); if (treatcleanupexceptionsasfatal) { throw e; public void startstopfilewatcher() throws InterruptedException { Thread t; synchronized (stopfilewatchercontrollock) { if (runstopfilewatcher) { return; stopfilewarcherloopstarted = false; runstopfilewatcher = true; System.out.println("Starting Stop File Watcher at: " + GetTimeStamp()); t = new Thread(stopFileWatcherRunner); t.start(); while (!stopfilewarcherloopstarted) { stopfilewatchercontrollock.wait();

12 System.out.println("Stop File Watcher Thread Started Running at: " + GetTimeStamp()); public void stopstopfilewatcher() throws InterruptedException { synchronized (stopfilewatchercontrollock) { if (!stopfilewarcherloopstarted!runstopfilewatcher) { return; System.out.println("Requesting Stop File Watcher Stop at: " + GetTimeStamp()); runstopfilewatcher = false; while (stopfilewarcherloopstarted) { stopfilewatchercontrollock.wait(); System.out.println("Stop File Watcher Stop Request Completed at: " + GetTimeStamp()); / This method is used to start the processing loop's thread. Again like the other methods in this section of the class, do not modify this method InterruptedException

13 @throws Exception / public void startprocessingloop() throws InterruptedException { Thread t; synchronized (loopcontrollock) { if (runprocessing) { return; loopstarted = false; runprocessing = true; rancleanup = false; System.out.println("Starting Processing Loop at: " + GetTimeStamp()); t = new Thread(executionLoopRunner); t.start(); while (!loopstarted) { loopcontrollock.wait(); System.out.println("Execution Processing Loop Thread Started Running at: " + GetTimeStamp()); / This method is used to stop or actually "request to stop" the processing

14 loop thread. It waits while the processing loop is InterruptedException / public void stopprocessingloop() throws InterruptedException { synchronized (loopcontrollock) { if (!loopstarted!runprocessing) { return; System.out.println("Requesting Execution Loop Stop at: " + GetTimeStamp()); runprocessing = false; while (loopstarted) { loopcontrollock.wait(); System.out.println("Execution Loop Stop Request Completed at: " + GetTimeStamp()); / This method will wait while the processing loop is running. Yes, I know we can use Thread.join(), however, what if you want to embedded this class in some other larger component, then you might not want to use the join method directly. I personally like this implementation better, it tells me exactly

15 what I'm waiting InterruptedException / public void waitwhileexecuting() throws InterruptedException { synchronized (loopcontrollock) { while (loopstarted) { loopcontrollock.wait(1000); / This is the runnable implementation as an anon inner class which contains the actual execution loop of the Daemon. This execution loop is what really separates the Daemon Process from the Standalone Process batch template. While the Standalone Process template was meant for processes which run a task and then exit once completed. This implementation is method to keep on running for extended periods of time, re-executing the custom processing logic over and over again after some sleep period. / private Runnable executionlooprunner = new Runnable() { public void run() { try { synchronized (loopcontrollock) { loopstarted = true; loopcontrollock.notifyall(); System.out.println("Executing Loop Thread Running!");

16 while (runprocessing) { // Hook to the User's Custom Execute Processing // Method! - Where the magic happens! customexecuteprocessing(); loopiterationcnt++; // Sleep between execution cycles try { for (int i = 1; runprocessing && i <= processloopsleepsecs; i++) { Thread.sleep(1000); catch (Exception e) { // End while runprocessing loop // End try block catch (Exception e) { e.printstacktrace(); finally { System.out.println("Execution Processing Loop Exit at: " + GetTimeStamp()); ; synchronized (loopcontrollock) { runprocessing = false; loopstarted = false; loopcontrollock.notifyall();

17 / This is the runnable implementation as an anon inner class which contains the Stop File Watcher loop. A Stop File Watcher is simply a standard file watcher, except when it finds the target file, it will execute the daemon shutdown routine. This is a form of inter-process communication via the file system to enable a separate process or even a simple script to control (or at least stop) the daemon process when it's running under NOHUP. You can simple create a script which creates an empty file using the unix TOUCH command. / private Runnable stopfilewatcherrunner = new Runnable() { public void run() { File f; try { synchronized (stopfilewatchercontrollock) { stopfilewarcherloopstarted = true; stopfilewatchercontrollock.notifyall(); System.out.println("Stop File Watcher Thread Running!"); f = new File(stopFilePath); while (runstopfilewatcher) { // If we find the stop file // stop the processing loop // and exit this thread as well. if (f.exists()) { System.out.println("Stop File: '" + stopfilepath + "' Found at: "

18 + GetTimeStamp()); stopprocessingloop(); break; ; // Sleep between file existence checks try { for (int i = 1; runstopfilewatcher && i <= stopfilesleepsecs; i++) { Thread.sleep(1000); catch (Exception e) { // End while runstopfilewatcher loop // End try block catch (Exception e) { e.printstacktrace(); finally { synchronized (stopfilewatchercontrollock) { runstopfilewatcher = false; stopfilewarcherloopstarted = false; stopfilewatchercontrollock.notifyall(); / This is the method that adds the shutdown hook. All this method does it property invokes the

19 Runtime.getRuntime().addShutdownHook(Thread t); method by adding an anonymous class implementation of a thread. This thread's run method simply calls the Process's cleanup method. Whenever I create a class like this, I envision it being ran two ways, either directly from the main() method or as part of a larger component, which may wrap this entire class (A HAS_A OOP relationship). In the case of the wrapper, adding the shutdown hook might be optional since the wrapper may want to handle shutdown on it's own. / public synchronized void addshutdownhook() { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { cleanup(); catch (Exception e) { e.printstacktrace(); ); / This method is only provided in case you are loading properties from an input stream or other non-standard source that is not a File. It becomes very useful in the wrapper class situation I described in the

20 comments about the addshutdownhook method. Perhaps the wrapping process reads properties from a Database or a appprops / public void setappproperties(properties appprops) { this.appprops = appprops; / Used to detect which mode the cleanup exceptions are handled / public boolean istreatcleanupexceptionsasfatal() { return treatcleanupexceptionsasfatal; / Use this method to set if you want to treat cleanup exception as fatal. The default, and my personal preference is not to make these exception fatal. But I added the flexibility into the template for your treatcleanupexceptionsasfatal / public void settreatcleanupexceptionsasfatal( boolean treatcleanupexceptionsasfatal) { this.treatcleanupexceptionsasfatal = treatcleanupexceptionsasfatal;

21 // > // Start methods that need to be customized by the user // > / In general for performance reasons and for clarity even above performance, I like pre-caching the properties as Strings or parsed Integers, etc, before running any real business logic. This is why I provide the hook to readproperties which should read properties from the appprops field (member variable). If you don't want to pre-cache your property values you can leave this method blank. However I believe it's a good practice especially if your batch process is a high speed ETL Loader process where every millisecond counts when loading millions of records. / private synchronized void readproperties() { System.out.println("Add Your Property Reads Here!"); / After the properties are read from the readproperties() method this method is called. It is provided for the user to add custom initialization processing. Let's say you want to open all JDBC connections at the start of a process, this is probably the right place to do so. For more complex implementations, this is the best place to create and initialize all your sub-components of your process.

22 Let's say you have a DbConnectionPool, a Country Code Mapping utility, an Address Fuzzy Logic Matching library. This is where I would initialize these components. The idea is to fail-fast in your batch processes, you don't want to wait until you processed 10,000 records before some logic statement is triggered to lazy instantiate these components, and because of a network issue or a configuration mistake you get a fatal exception and your process exists, and your data is only partially loaded and you or your production support team members have to debug not only the process but debug the portion of the data already loaded make it in ok. This is extremely important if your batch process interacts is real-time system components such as message publishers, maybe you started publishing the updated records to downstream consumers? Fail-Fast my friends... And as soon as the process starts if possible! / private synchronized void customprocessinit() { System.out.println("Add Custom Initialization Logic Here!"); / This is where you would add your custom cleanup processing. If you open and connections, files, sockets, etc and keep references to these objects/resources opened as fields in your class which is a good idea in some cases especially long running batch processes you need a hook to be able to close these resources before the process exits. This is where that type of logic should be placed.

23 Now you can throw any exception you like, however the cleanup wrapper method will simply log these exceptions, the idea here is that, even though cleanup is extremely important, the next step of the process is a System.exit and the operating system will most-likely reclaim any resources such as files and sockets which have been left opened, after some bit of time. Now my preference is usually not to wake my production support guys up because a database connection (on the extremely rare occasion) didn't close correctly. The process still ran successfully at this point, so just exit and log it. However if you really need to make the cleanup be truly fatal to the process you will have to set treatcleanupexceptionsasfatal to Exception / private synchronized void customprocesscleanup() throws Exception { System.out.println("Add Custom Cleanup Logic Here!"); private synchronized void customexecuteprocessing() throws Exception { System.out.println("Loop Iteration Count = " + loopiterationcnt + " - Add Custom Processing Logic Here!"); // Uncomment for testing if you want to see the behavior... if (loopiterationcnt == 5) { throw new Exception( "Testing what happens if an exception gets thrown here!");

24 // > / Start String Utility Methods These are methods I have in my custom "StringUtils.java" class I extracted them and embedded them in this class for demonstration purposes. I encourage everyone to build up their own set of useful String Utility Functions please feel free to add these to your own set if you need them. / // > / This will return a string that is a human readable time sentence. It is the "compact" version because instead of having leading ZERO Days, Hours, Minutes, Seconds, it will only start the sentence with the first non-zero time unit. In my string utils I have a non-compact version as well that prints the leading zero time units. All depends on how you need to presented in your logs. / public static String CompactHumanReadableTimeWithMs(long milliseconds) { long days, hours, inpsecs, leftoverms; int minutes, seconds; StringBuffer sb = new StringBuffer(); inpsecs = milliseconds / 1000; // Convert Milliseconds into Seconds days = inpsecs / 86400; hours = (inpsecs - (days 86400)) / 3600;

25 minutes = (int) (((inpsecs - (days 86400)) - (hours 3600)) / 60); seconds = (int) (((inpsecs - (days 86400)) - (hours 3600)) - (minutes 60)); leftoverms = milliseconds - (inpsecs 1000); if (days > 0) { sb.append(days); sb.append((days!= 1? " Days" : " Day")); if (sb.length() > 0) { sb.append(", "); if (hours > 0 sb.length() > 0) { sb.append(hours); sb.append((hours!= 1? " Hours" : " Hour")); if (sb.length() > 0) { sb.append(", "); if (minutes > 0 sb.length() > 0) { sb.append(minutes); sb.append((minutes!= 1? " Minutes" : " Minute")); if (sb.length() > 0) { sb.append(", ");

26 if (seconds > 0 sb.length() > 0) { sb.append(seconds); sb.append((seconds!= 1? " Seconds" : " Second")); if (sb.length() > 0) { sb.append(", "); sb.append(leftoverms); sb.append((seconds!= 1? " Milliseconds" : " Millisecond")); return sb.tostring(); / NVL = Null Value, in my experience, most times, we want to treat empty or whitespace only strings are NULLs So this method is here to avoid a lot of if (s == null s.trim().length() == 0) all over the place, instead you will find if(isnvl(s)) instead. / public static boolean IsNVL(String s) { return s == null s.trim().length() == 0; / Check is "s" is a numeric value We could use Integer.praseInt and just capture the exception if it's not a number, but I think that's a s

27 @return / public static boolean IsNumeric(String s) { boolean numeric = false; char c; if (!IsNVL(s)) { numeric = true; s = s.trim(); for (int i = 0; i < s.length(); i++) { c = s.charat(i); if (i == 0 && (c == '-' c == '+')) { // Ignore signs... continue; else if (c < '0' c > '9') { numeric = false; break; return numeric; / Simply returns a timestamp as a

28 / public static String GetTimeStamp() { return (new java.util.date()).tostring(); // > // Start Main() Helper Static Methods // > / This method returns true if the command line arguments are valid, and false otherwise. Please change this method to meet your implementation's requirements. / private static boolean CheckCommandLineArguments(String[] args) { boolean ok = false; ok = args.length == 4 &&!IsNVL(args[0]) && IsNumeric(args[1]) &&!IsNVL(args[2]) && IsNumeric(args[3]); return ok; / This prints to STDERR (a common practice), the command line usage of the program. Please change this to meet your implementation's command line arguments. / private static void PrintUsage() { StringBuffer sb = new StringBuffer();

29 sb.append("\nusage: java "); sb.append(donothingstandalonedaemon.class.getname()); / Modify this append call to have each command line argument name example: sb.append( " [APP_PROPERTIES_FILE] [SOURCE_INPUT_FILE] [WSDL_URL] [TARGET_OUTPUT_FILE]" ); For demo purposes we will only use [APP_PROPERTIES_FILE] / sb.append(" [APP_PROPERTIES_FILE] [PROCESS_LOOP_SLEEP_SECONDS] [STOP_FILE_PATH] [STOP_WATCHER_SECONDS]"); sb.append("\n\n"); System.err.print(sb.toString()); / I usually like the Batch and Daemon Processes or Utilities to print a small Banner at the top of their output. Please change this to suit your needs. / private static void PrintWelcome() { StringBuffer sb = new StringBuffer(); sb.append("\n\n"); sb.append(" Do Nothing Standalone Daemon \n"); sb.append("\n\n"); System.out.print(sb.toString());

30 / This method simple prints the process startup time. I found this to be very useful in batch job logs. I probably wouldn't change it, but you can if you really need to. / private static void PrintStartupTime() { StringBuffer sb = new StringBuffer(); sb.append("startup Time: "); sb.append(gettimestamp()); sb.append("\n\n"); System.out.print(sb.toString()); // Start Main() Method // > / Here's your standard main() method which allows you to start a Java program from the command line. You can probably use this as is, once you rename the DoNothingStandaloneProcess class name to a proper name to represent your implementation correctly. MAKE SURE: To change the data type of the process object reference to the name of your process implementation class. Other than that, you are good to go with this main method! / public static void main(string[] args) { int exitcode; DoNothingStandaloneDaemon daemon = null; if (!CheckCommandLineArguments(args)) { PrintUsage();

31 exitcode = 1; else { try { PrintWelcome(); PrintStartupTime(); daemon = new DoNothingStandaloneDaemon(); // I don't believe cleanup exceptions // area really fatal, but that's up to you... daemon.settreatcleanupexceptionsasfatal(false); // Load properties using the file way. daemon.loadproperties(args[0]); // Set process loop sleep seconds daemon.setprocessloopsleepsecond(integer.parseint(args[1])); // Set the stop file watcher file path daemon.setstopfilepath(args[2]); // Set the stop file watcher sleep seconds daemon.setstopfilewatchersleepseconds(integer.parseint(args[3])); // Performance daemon Initialization, // again I don't like over use of the constructor. daemon.init(); daemon.addshutdownhook(); // Just in case we get an interrupt signal... // Star the Stop File Watcher!

32 // It is not enabled automatically // to make this template more flexible // if you want to embedded it in a larger component daemon.startstopfilewatcher(); // Do the actually business logic execution! // If we made it to this point without an exception, that means // we are successful, the daemon exit code should be ZERO for SUCCESS! daemon.startprocessingloop(); // Wait while the execution loop is running! daemon.waitwhileexecuting(); exitcode = 0; // End try block catch (Exception e) { exitcode = 1; // If there was an exception, the daemon exit code should // be NON-ZERO for FAILURE! e.printstacktrace(); // Log the exception, if you have an Exception // utility like I do, use that instead. finally { if (daemon!= null) { try { daemon.stopstopfilewatcher(); // Just in case stop file watcher catch (Exception e) { e.printstacktrace();

33 try { daemon.stopprocessingloop(); // Just in case stop processing loop catch (Exception e) { e.printstacktrace(); try { // Technically we don't need to do this because // of the shutdown hook // But I like to be explicit here to show when during a // normal execution, when the call // to cleanup should happen. daemon.cleanup(); catch (Exception e) { // We shouldn't receive an exception // But in case there is a runtime exception // Just print it, but treat it as non-fatal. // Technically most if not all resources // will be reclaimed by the operating system as an // absolute last resort // so we did our best attempt at cleaning things up, // but we don't want to wake our developers or our // production services team // up at 3 in the morning because something weird // happened during cleanup. e.printstacktrace(); // If we set the daemon to treat cleanup exception as fatal // the exit code will be set to 1...

34 if (daemon!= null && daemon.istreatcleanupexceptionsasfatal()) { exitcode = 1; // End finally block // End else block // Make sure our standard streams are flushed // so we don't miss anything in the logs. System.out.flush(); System.err.flush(); System.out.println("Daemon Exit Code = " + exitcode); System.out.flush(); // Make sure to return the exit code to the parent process System.exit(exitCode); // >

/* Copyright 2012 Robert C. Ilardi

/* Copyright 2012 Robert C. Ilardi / Copyright 2012 Robert C. Ilardi Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

More information

Multithreaded Programming

Multithreaded Programming Multithreaded Programming Multithreaded programming basics Concurrency is the ability to run multiple parts of the program in parallel. In Concurrent programming, there are two units of execution: Processes

More information

Threads and Java Memory Model

Threads and Java Memory Model Threads and Java Memory Model Oleg Šelajev @shelajev oleg@zeroturnaround.com October 6, 2014 Agenda Threads Basic synchronization Java Memory Model Concurrency Concurrency - several computations are executing

More information

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03 CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03 Topics: Threading, Synchronization 1 Threading Suppose we want to create an automated program that hacks into a server. Many encryption

More information

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions

G51PGP Programming Paradigms. Lecture 009 Concurrency, exceptions G51PGP Programming Paradigms Lecture 009 Concurrency, exceptions 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals = new Animal[6]; animals[0]

More information

CSC Java Programming, Fall Java Data Types and Control Constructs

CSC Java Programming, Fall Java Data Types and Control Constructs CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference

More information

Exercise Session Week 8

Exercise Session Week 8 Chair of Software Engineering Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exercise Session Week 8 Java 8 release date Was early September 2013 Currently moved to March 2014 http://openjdk.java.net/projects/jdk8/milestones

More information

Exercise Session Week 8

Exercise Session Week 8 Chair of Software Engineering Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exercise Session Week 8 Quiz 1: What is printed? (Java) class MyTask implements Runnable { public void

More information

CS193k, Stanford Handout #8. Threads 3

CS193k, Stanford Handout #8. Threads 3 CS193k, Stanford Handout #8 Spring, 2000-01 Nick Parlante Threads 3 t.join() Wait for finish We block until the receiver thread exits its run(). Use this to wait for another thread to finish. The current

More information

Threads Chate Patanothai

Threads Chate Patanothai Threads Chate Patanothai Objectives Knowing thread: 3W1H Create separate threads Control the execution of a thread Communicate between threads Protect shared data C. Patanothai Threads 2 What are threads?

More information

CMSC 132: Object-Oriented Programming II. Threads in Java

CMSC 132: Object-Oriented Programming II. Threads in Java CMSC 132: Object-Oriented Programming II Threads in Java 1 Problem Multiple tasks for computer Draw & display images on screen Check keyboard & mouse input Send & receive data on network Read & write files

More information

16-Dec-10. Consider the following method:

16-Dec-10. Consider the following method: Boaz Kantor Introduction to Computer Science IDC Herzliya Exception is a class. Java comes with many, we can write our own. The Exception objects, along with some Java-specific structures, allow us to

More information

Threads. Fundamentals of Computer Science

Threads. Fundamentals of Computer Science Threads Fundamentals of Computer Science Outline Multi-threaded programs Multiple simultaneous paths of execution Seemingly at once (single core) Actually at the same time (multiple cores) Why? Get work

More information

7. MULTITHREDED PROGRAMMING

7. MULTITHREDED PROGRAMMING 7. MULTITHREDED PROGRAMMING What is thread? A thread is a single sequential flow of control within a program. Thread is a path of the execution in a program. Muti-Threading: Executing more than one thread

More information

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit

Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multit Threads Multitasking Multitasking allows several activities to occur concurrently on the computer. A distinction is usually made between: Process-based multitasking Thread-based multitasking Multitasking

More information

Core Java Interview Questions and Answers.

Core Java Interview Questions and Answers. Core Java Interview Questions and Answers. Q: What is the difference between an Interface and an Abstract class? A: An abstract class can have instance methods that implement a default behavior. An Interface

More information

Programming Assignment Comma Separated Values Reader Page 1

Programming Assignment Comma Separated Values Reader Page 1 Programming Assignment Comma Separated Values Reader Page 1 Assignment What to Submit 1. Write a CSVReader that can read a file or URL that contains data in CSV format. CSVReader provides an Iterator for

More information

Brief Summary of Java

Brief Summary of Java Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java

More information

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently. Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently. User Request: Create a simple movie data system. Milestones: 1. Use

More information

Note: Each loop has 5 iterations in the ThreeLoopTest program.

Note: Each loop has 5 iterations in the ThreeLoopTest program. Lecture 23 Multithreading Introduction Multithreading is the ability to do multiple things at once with in the same application. It provides finer granularity of concurrency. A thread sometimes called

More information

Chapter 3: A Larger Example: SocketChat

Chapter 3: A Larger Example: SocketChat page 1 Chapter 3: A Larger Example: SocketChat In this chapter we are going to look at three versions of a larger socket-based example: a simple `chat' application. The application does not have many capabilities,

More information

Answer Key. 1. General Understanding (10 points) think before you decide.

Answer Key. 1. General Understanding (10 points) think before you decide. Answer Key 1. General Understanding (10 points) Answer the following questions with yes or no. think before you decide. Read the questions carefully and (a) (2 points) Does the interface java.util.sortedset

More information

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007 CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Threads and Synchronization May 8, 2007 Computation Abstractions t1 t1 t4 t2 t1 t2 t5 t3 p1 p2 p3 p4 CPU 1 CPU 2 A computer Processes

More information

JUnit Test Patterns in Rational XDE

JUnit Test Patterns in Rational XDE Copyright Rational Software 2002 http://www.therationaledge.com/content/oct_02/t_junittestpatternsxde_fh.jsp JUnit Test Patterns in Rational XDE by Frank Hagenson Independent Consultant Northern Ireland

More information

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Lecture 04 Software Test Automation: JUnit as an example

More information

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014 CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2014 Name: This exam consists of 5 problems on the following 6 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet

More information

Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure.

Java in 21 minutes. Hello world. hello world. exceptions. basic data types. constructors. classes & objects I/O. program structure. Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static

More information

CmpSci 187: Programming with Data Structures Spring 2015

CmpSci 187: Programming with Data Structures Spring 2015 CmpSci 187: Programming with Data Structures Spring 2015 Lecture #13, Concurrency, Interference, and Synchronization John Ridgway March 12, 2015 Concurrency and Threads Computers are capable of doing more

More information

Definition: A thread is a single sequential flow of control within a program.

Definition: A thread is a single sequential flow of control within a program. What Is a Thread? All programmers are familiar with writing sequential programs. You've probably written a program that displays "Hello World!" or sorts a list of names or computes a list of prime numbers.

More information

Handouts. 1 Handout for today! Recap. Homework #2 feedback. Last Time. What did you think? HW3a: ThreadBank. Today. Small assignment.

Handouts. 1 Handout for today! Recap. Homework #2 feedback. Last Time. What did you think? HW3a: ThreadBank. Today. Small assignment. Handouts CS193J: Programming in Java Summer Quarter 2003 Lecture 10 Thread Interruption, Cooperation (wait/notify), Swing Thread, Threading conclusions 1 Handout for today! #21: Threading 3 #22: HW3a:

More information

Threads and Locks. CSCI 5828: Foundations of Software Engineering Lecture 09 09/22/2015

Threads and Locks. CSCI 5828: Foundations of Software Engineering Lecture 09 09/22/2015 Threads and Locks CSCI 5828: Foundations of Software Engineering Lecture 09 09/22/2015 1 Goals Cover the material presented in Chapter 2, Day 1 of our concurrency textbook Creating threads Locks Memory

More information

CS193j, Stanford Handout #25. Exceptions

CS193j, Stanford Handout #25. Exceptions CS193j, Stanford Handout #25 Summer, 2003 Manu Kumar Exceptions Great Exceptations Here we'll cover the basic features and uses of exceptions. Pre-Exceptions A program has to encode two ideas -- how to

More information

40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the

40) Class can be inherited and instantiated with the package 41) Can be accessible anywhere in the package and only up to sub classes outside the Answers 1) B 2) C 3) A 4) D 5) Non-static members 6) Static members 7) Default 8) abstract 9) Local variables 10) Data type default value 11) Data type default value 12) No 13) No 14) Yes 15) No 16) No

More information

CS 11 java track: lecture 3

CS 11 java track: lecture 3 CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Chapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved.

Chapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved. Chapter 9 Exception Handling Copyright 2016 Pearson Inc. All rights reserved. Last modified 2015-10-02 by C Hoang 9-2 Introduction to Exception Handling Sometimes the best outcome can be when nothing unusual

More information

Reading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.

Reading from URL. Intent - open URL  get an input stream on the connection, and read from the input stream. Simple Networking Loading applets from the network. Applets are referenced in a HTML file. Java programs can use URLs to connect to and retrieve information over the network. Uniform Resource Locator (URL)

More information

20 Most Important Java Programming Interview Questions. Powered by

20 Most Important Java Programming Interview Questions. Powered by 20 Most Important Java Programming Interview Questions Powered by 1. What's the difference between an interface and an abstract class? An abstract class is a class that is only partially implemented by

More information

Michele Van Dyne MUS 204B https://katie.mtech.edu/classes/csci136. Threads

Michele Van Dyne MUS 204B https://katie.mtech.edu/classes/csci136. Threads Michele Van Dyne MUS 204B mvandyne@mtech.edu https://katie.mtech.edu/classes/csci136 Threads Multi-threaded programs Multiple simultaneous paths of execution Seemingly at once (single core) Actually at

More information

Exceptions. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. CSE 142, Summer 2002 Computer Programming 1. Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ 12-Aug-2002 cse142-19-exceptions 2002 University of Washington 1 Reading Readings and References»

More information

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1. Readings and References Exceptions CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ Reading» Chapter 18, An Introduction to Programming and Object Oriented

More information

MultiThreading 07/01/2013. Session objectives. Introduction. Introduction. Advanced Java Programming Course

MultiThreading 07/01/2013. Session objectives. Introduction. Introduction. Advanced Java Programming Course Advanced Java Programming Course MultiThreading By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City Session objectives Introduction Creating thread Thread class

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages References Exceptions "Handling Errors with Exceptions", Java tutorial http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/

More information

Advanced Java Programming Course. MultiThreading. By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City

Advanced Java Programming Course. MultiThreading. By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City Advanced Java Programming Course MultiThreading By Võ Văn Hải Faculty of Information Technologies Industrial University of Ho Chi Minh City Session objectives Introduction Creating thread Thread class

More information

Software Practice 1 - Multithreading

Software Practice 1 - Multithreading Software Practice 1 - Multithreading What is the thread Life cycle of thread How to create thread Thread method Lab practice Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim T.A. Sujin Oh Junseong Lee

More information

1.00 Introduction to Computers and Engineering Problem Solving. Final Examination - May 19, 2004

1.00 Introduction to Computers and Engineering Problem Solving. Final Examination - May 19, 2004 1.00 Introduction to Computers and Engineering Problem Solving Final Examination - May 19, 2004 Name: E-mail Address: TA: Section: You have 3 hours to complete this exam. For coding questions, you do not

More information

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Third Look At Java Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Little Demo public class Test { public static void main(string[] args) { int i = Integer.parseInt(args[0]); int j = Integer.parseInt(args[1]);

More information

UNIT V CONCURRENT PROGRAMMING

UNIT V CONCURRENT PROGRAMMING UNIT V CONCURRENT PROGRAMMING Multi-Threading: Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run concurrently. Each part of such

More information

Java Threads. COMP 585 Noteset #2 1

Java Threads. COMP 585 Noteset #2 1 Java Threads The topic of threads overlaps the boundary between software development and operation systems. Words like process, task, and thread may mean different things depending on the author and the

More information

JAVA BASICS II. Example: FIFO

JAVA BASICS II. Example: FIFO JAVA BASICS II Example: FIFO To show how simple data structures are built without pointers, we ll build a doubly-linked list ListItem class has some user data first refers to that ListItem object at the

More information

Concurrent Programming. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University

Concurrent Programming. Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University Concurrent Programming Copyright 2017 by Robert M. Dondero, Ph.D. Princeton University 1 Objectives You will learn/review: What a process is How to fork and wait for processes What a thread is How to spawn

More information

The University of Melbourne Department of Computer Science and Software Engineering Software Design Semester 2, 2003

The University of Melbourne Department of Computer Science and Software Engineering Software Design Semester 2, 2003 The University of Melbourne Department of Computer Science and Software Engineering 433-254 Software Design Semester 2, 2003 Answers for Tutorial 7 Week 8 1. What are exceptions and how are they handled

More information

CS11 Java. Fall Lecture 4

CS11 Java. Fall Lecture 4 CS11 Java Fall 2014-2015 Lecture 4 Java File Objects! Java represents files with java.io.file class " Can represent either absolute or relative paths! Absolute paths start at the root directory of the

More information

CS 351 Design of Large Programs Threads and Concurrency

CS 351 Design of Large Programs Threads and Concurrency CS 351 Design of Large Programs Threads and Concurrency Brooke Chenoweth University of New Mexico Spring 2018 Concurrency in Java Java has basic concurrency support built into the language. Also has high-level

More information

CS 3 Introduction to Software Engineering. 3: Exceptions

CS 3 Introduction to Software Engineering. 3: Exceptions CS 3 Introduction to Software Engineering 3: Exceptions Questions? 2 Objectives Last Time: Procedural Abstraction This Time: Procedural Abstraction II Focus on Exceptions. Starting Next Time: Data Abstraction

More information

Smart formatting for better compatibility between OpenOffice.org and Microsoft Office

Smart formatting for better compatibility between OpenOffice.org and Microsoft Office Smart formatting for better compatibility between OpenOffice.org and Microsoft Office I'm going to talk about the backbreaking labor of helping someone move and a seemingly unrelated topic, OpenOffice.org

More information

Exam Questions 1Z0-895

Exam Questions 1Z0-895 Exam Questions 1Z0-895 Java Platform, Enterprise Edition 6 Enterprise JavaBeans Developer Certified Expert Exam https://www.2passeasy.com/dumps/1z0-895/ QUESTION NO: 1 A developer needs to deliver a large-scale

More information

6.001 Notes: Section 17.5

6.001 Notes: Section 17.5 6.001 Notes: Section 17.5 Slide 17.5.1 Now, let's look at one example in which changing the evaluation model allows us to explore a very different kind of computational problem. Our goal is to show how

More information

Using Properties for runtime ICAN 5.0.x JCD Configuration

Using Properties for runtime ICAN 5.0.x JCD Configuration Using Properties for runtime ICAN 5.0.x JCD Configuration Michael Czapski OCTOBER 2004 Page 1 of 13 Table of Contents Introduction... 3 IS JVM Properties... 4 Setting... 4 Propagating to Runtime... 5 Using

More information

Animation Part 2: MoveableShape interface & Multithreading

Animation Part 2: MoveableShape interface & Multithreading Animation Part 2: MoveableShape interface & Multithreading MoveableShape Interface In the previous example, an image was drawn, then redrawn in another location Since the actions described above can apply

More information

Contents. 6-1 Copyright (c) N. Afshartous

Contents. 6-1 Copyright (c) N. Afshartous Contents 1. Classes and Objects 2. Inheritance 3. Interfaces 4. Exceptions and Error Handling 5. Intro to Concurrency 6. Concurrency in Java 7. Graphics and Animation 8. Applets 6-1 Copyright (c) 1999-2004

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Chapter 6 Parallel Loops

Chapter 6 Parallel Loops Chapter 6 Parallel Loops Part I. Preliminaries Part II. Tightly Coupled Multicore Chapter 6. Parallel Loops Chapter 7. Parallel Loop Schedules Chapter 8. Parallel Reduction Chapter 9. Reduction Variables

More information

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks) M257 MTA Spring2010 Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks) 1. If we need various objects that are similar in structure, but

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Lesson 3 Transcript: Part 2 of 2 Tools & Scripting

Lesson 3 Transcript: Part 2 of 2 Tools & Scripting Lesson 3 Transcript: Part 2 of 2 Tools & Scripting Slide 1: Cover Welcome to lesson 3 of the DB2 on Campus Lecture Series. Today we are going to talk about tools and scripting. And this is part 2 of 2

More information

05. SINGLETON PATTERN. One of a Kind Objects

05. SINGLETON PATTERN. One of a Kind Objects BIM492 DESIGN PATTERNS 05. SINGLETON PATTERN One of a Kind Objects Developer: What use is that? Guru: There are many objects we only need one of: thread pools, caches, dialog boxes, objects that handle

More information

Chair of Software Engineering. Java and C# in Depth. Prof. Dr. Bertrand Meyer. Exercise Session 8. Nadia Polikarpova

Chair of Software Engineering. Java and C# in Depth. Prof. Dr. Bertrand Meyer. Exercise Session 8. Nadia Polikarpova Chair of Software Engineering Java and C# in Depth Prof. Dr. Bertrand Meyer Exercise Session 8 Nadia Polikarpova Quiz 1: What is printed? (Java) class MyTask implements Runnable { «Everything is ok! public

More information

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems : Organization of Programming Languages Threads Classic Concurrency Problems The Dining Philosophers Problem Philosophers either eat or think They must have two forks to eat Can only use forks on either

More information

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15 Table of Contents 1 INTRODUCTION... 1 2 IF... 1 2.1 BOOLEAN EXPRESSIONS... 3 2.2 BLOCKS... 3 2.3 IF-ELSE... 4 2.4 NESTING... 5 3 SWITCH (SOMETIMES KNOWN AS CASE )... 6 3.1 A BIT ABOUT BREAK... 7 4 CONDITIONAL

More information

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction CS106L Spring 2009 Handout #21 May 12, 2009 static Introduction Most of the time, you'll design classes so that any two instances of that class are independent. That is, if you have two objects one and

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE Program 10: 40 points: Due Tuesday, May 12, 2015 : 11:59 p.m. ************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE *************

More information

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently. Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently. User Request: Create a simple magazine data system. Milestones:

More information

Who am I? I m a python developer who has been working on OpenStack since I currently work for Aptira, who do OpenStack, SDN, and orchestration

Who am I? I m a python developer who has been working on OpenStack since I currently work for Aptira, who do OpenStack, SDN, and orchestration Who am I? I m a python developer who has been working on OpenStack since 2011. I currently work for Aptira, who do OpenStack, SDN, and orchestration consulting. I m here today to help you learn from my

More information

COMPSCI 230 Threading Week8. Figure 1 Thread status diagram [http://www.programcreek.com/2009/03/thread-status/]

COMPSCI 230 Threading Week8. Figure 1 Thread status diagram [http://www.programcreek.com/2009/03/thread-status/] COMPSCI 230 Threading Week8 Figure 1 Thread status diagram [http://www.programcreek.com/2009/03/thread-status/] Synchronization Lock DeadLock Why do we need Synchronization in Java? If your code is executing

More information

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1 Shell Scripting Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 If we have a set of commands that we want to run on a regular basis, we could write a script A script acts as a Linux command,

More information

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07 Informatica 3 Marcello Restelli 9/15/07 10/29/07 Laurea in Ingegneria Informatica Politecnico di Milano Structuring the Computation Control flow can be obtained through control structure at instruction

More information

CS193k, Stanford Handout #12. Threads 4 / RMI

CS193k, Stanford Handout #12. Threads 4 / RMI CS193k, Stanford Handout #12 Spring, 99-00 Nick Parlante Threads 4 / RMI Semaphore1 Semaphore1 from last time uses the count in a precise way to know exactly how many threads are waiting. In this way,

More information

Single processor CPU. Memory I/O

Single processor CPU. Memory I/O Lec 17 Threads Single processor CPU Memory I/O Multi processes Eclipse PPT iclicker Multi processor CPU CPU Memory I/O Multi-core Core Core Core Core Processor Memory I/O Logical Cores Multi-threaded

More information

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully

More information

Chapter 10 Recursion

Chapter 10 Recursion Chapter 10 Recursion Written by Dr. Mark Snyder [minor edits for this semester by Dr. Kinga Dobolyi] Recursion implies that something is defined in terms of itself. We will see in detail how code can be

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Project #1: Tracing, System Calls, and Processes

Project #1: Tracing, System Calls, and Processes Project #1: Tracing, System Calls, and Processes Objectives In this project, you will learn about system calls, process control and several different techniques for tracing and instrumenting process behaviors.

More information

Slide 1 CS 170 Java Programming 1 Testing Karel

Slide 1 CS 170 Java Programming 1 Testing Karel CS 170 Java Programming 1 Testing Karel Introducing Unit Tests to Karel's World Slide 1 CS 170 Java Programming 1 Testing Karel Hi Everybody. This is the CS 170, Java Programming 1 lecture, Testing Karel.

More information

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE

More information

Core Java Syllabus. Overview

Core Java Syllabus. Overview Core Java Syllabus Overview Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java

More information

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between MITOCW Lecture 10A [MUSIC PLAYING] PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between all these high-level languages like Lisp and the query

More information

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015

CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015 CSCI 136 Written Exam #1 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 5 problems on the following 7 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet

More information

Unit 5 - Exception Handling & Multithreaded

Unit 5 - Exception Handling & Multithreaded Exceptions Handling An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/application

More information

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166 Lecture 20 Java Exceptional Event Handling Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics What is an Exception? Exception Handler Catch or Specify Requirement Three Kinds of Exceptions

More information

CSCD 330 Network Programming

CSCD 330 Network Programming CSCD 330 Network Programming Lecture 12 More Client-Server Programming Winter 2019 Reading: References at end of Lecture 1 Introduction So far, Looked at client-server programs with Java Sockets TCP and

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

CPS221 Lecture: Threads

CPS221 Lecture: Threads Objectives CPS221 Lecture: Threads 1. To introduce threads in the context of processes 2. To introduce UML Activity Diagrams last revised 9/5/12 Materials: 1. Diagram showing state of memory for a process

More information

Chapter 17 vector and Free Store

Chapter 17 vector and Free Store Chapter 17 vector and Free Store Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/~hkaiser/fall_2010/csc1253.html Slides adapted from: Bjarne Stroustrup, Programming Principles and Practice using

More information

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17 Concurrency & Parallelism So far, our programs have been sequential: they do one thing after another, one thing at a. Let s start writing programs that do more than one thing at at a. Threads, Concurrency,

More information

Robotics and Autonomous Systems

Robotics and Autonomous Systems 1 / 38 Robotics and Autonomous Systems Lecture 10: Threads and Multitasking Robots Simon Parsons Department of Computer Science University of Liverpool 2 / 38 Today Some more programming techniques that

More information

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1 P a g e 1 CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1 Q1 Describe some Characteristics/Advantages of Java Language? (P#12, 13, 14) 1. Java

More information

17. Handling Runtime Problems

17. Handling Runtime Problems Handling Runtime Problems 17.1 17. Handling Runtime Problems What are exceptions? Using the try structure Creating your own exceptions Methods that throw exceptions SKILLBUILDERS Handling Runtime Problems

More information