Austin Java Users Group developerWorks article – µActor Library BARRY FEIGENBAUM, PH. D. 02/26/13.

Slides:



Advertisements
Similar presentations
© 2007 Eaton Corporation. All rights reserved. LabVIEW State Machine Architectures Presented By Scott Sirrine Eaton Corporation.
Advertisements

3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Operating Systems Lecture 7.
CSCC69: Operating Systems
Multithreaded Programs in Java. Tasks and Threads A task is an abstraction of a series of steps – Might be done in a separate thread – Java libraries.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
Introduction CSCI 444/544 Operating Systems Fall 2008.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 5: Threads 9/29/03+ Overview Benefits User and Kernel Threads Multithreading.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Threading in Java – a Tutorial QMUL IEEE SB. Why Threading When we need to run two tasks concurrently So multiple parts (>=2) of a program can run simultaneously.
OOP Languages: Java vs C++
Real-Time Software Design Yonsei University 2 nd Semester, 2014 Sanghyun Park.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Collage of Information Technology University of Palestine Advanced programming MultiThreading 1.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Threads A thread (or lightweight process) is a basic unit of CPU.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
10/17/2015Vimal1 Threads By 10/17/2015Vimal2 Why use threads?? It is a powerful programming tool Computer users take it for granted.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Practical OOP using Java Basis Faqueer Tanvir Ahmed, 08 Jan 2012.
Dynamic Architectures (Component Reconfiguration) with Fractal.
Concurrent Programming and Threads Threads Blocking a User Interface.
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
Advanced Concurrency Topics Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Concurrency Control 1 Fall 2014 CS7020: Game Design and Development.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Multi-Threading in Java
Threads. Readings r Silberschatz et al : Chapter 4.
2/20/2016 EEC492/693/793 - iPhone Application Development 12/20/2016 EEC492/693/793 - iPhone Application Development 1 EEC-492/693/793 iPhone Application.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4 – Thread Concepts
Chapter 4: Multithreaded Programming
A brief intro to: Parallelism, Threads, and Concurrency
Topic 3 (Textbook - Chapter 3) Processes
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Concurrency, Processes and Threads
Chapter 4 – Thread Concepts
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Operating System (013022) Dr. H. Iwidat
Threads and Cooperation
Threads, SMP, and Microkernels
Realizing Concurrency using the thread model
Android Topics UI Thread and Limited processing resources
Threads Chapter 4.
Chapter 4 Threads, SMP, and Microkernels
Realizing Concurrency using the thread model
(Computer fundamental Lab)
Chapter 4: Threads & Concurrency
Chapter 4: Threads.
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Outline Chapter 3: Processes Chapter 4: Threads So far - Next -
Concurrency, Processes and Threads
Chapter 4: Threads.
Software Engineering and Architecture
Presentation transcript:

Austin Java Users Group developerWorks article – µActor Library BARRY FEIGENBAUM, PH. D. 02/26/13

Brief Bio  I have Ph.D. in Computer Engineering  I have been developing software for more than 30 years  I have worked at IBM, Amazon, Dell and others.  I have worked as a developer, designer, team lead, architect and manager  I have worked on business applications, operating systems, tools, web application, etc.  I have been using Java since version  I am Oracle certified: Java Programmer, Java Developer, Architect for Java Technology  I have written several books and articles; I have numerous US patents

Topics  Background  Actor Library Design and Implementation  Sample Actor  Demo

Background  Moore’s Law: due to heat dissipation issues moving from faster and faster CPU speed to more copies (i.e., cores) of a CPU per processor  Most computers have multiple cores and the number is increasing over time  Automatic speed up no longer occurring; programs must become much more concurrent to exploit these cores  Traditional imperative languages do this poorly  Hard to code; requires high skill  Near impossible to test correct implementations  Something simpler, such as the Actor Model, is needed

Background (cont)  Newer languages offering solutions  Concurrency Libraries  Built-in Language Facilities (ex. Actors; Functional (no side-effects) orientation)  Etc.  JRE provides support but at too low a level  threads  synchronized blocks  java.util.concurrent

µActor Library  This presentation concentrates on a Java library for exploiting the Actor model  Wikipedia: The Actor model in computer science is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent digital computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message received.computer science concurrent computation  This library can be used by any Java 6+ application

µActor Library (cont)  Lightweight and easy to use  Pure-Java library (no AOP, etc.)  Configurable and dynamic  Key Concepts (interfaces with default implementations)  Actor – unit of execution; processes 1 message at a time  Message – defines an action, has from/to/subject/data/+  ActorManager – manages actors; allocates threads to actors to process messages

Actor Runtime Model  Managers own 0+ Actors  Managers manage 0+ Threads  Actors buffer 0+ Messages  Managers send messages to Actors  Actors use Threads to process messages Manager Actor Message * * Thread * Per Message

ActorManager  Actor lifetime management  Actor runtime lifecycle management  Message sending services  DefaultActorManager implementation  Adds more API, including thread pool management

Actor extends Runnable  Message processing and capacity  Distinct identity, category  Lifecycle, belongs to only one manager  AbstractActor partial implementation  Adds some more services  Multiple levels of subclasses possible

Actor Lifecycle 1. New 2. Activate 3. Run 4. Receive (repeated) 5. Deactivate 6. Garbage Activated Run Deactivated Idle Receive Suspended Shutdown New Consumes thread in receive state

Message  Message body  Sender, subject, data  Optional but typical  Target supplied via send operation  Added to message by send code  DefaultMessage implementation  Multiple levels of subclasses possible

Execution Model  Multiple actors, possibly of different types, cooperate by sending messages to each other.  Sends can fail - count limit exceeded, bad subject, etc.  Each actor has a queue of pending (received) messages.  When a thread is available, the manager dispatches an actor’s receive method passing in the next message.  Receive should be short lived

TestActor  A sample actor  Repeats sends count down  Define lifecycle callback methods (for illustration)  Define on start callback public class TestActor extends TestableActor public void activate() { super.activate(); public void deactivate() { super.deactivate(); protected void runBody() { DefaultMessage m = new DefaultMessage("init", 8); getManager().send(m, null, this); }

TestActor (cont)  Assume superclass has overridden receive to call loopBody  Process repeat message  Repeat send N-1 times to random protected void loopBody(Message m) { String subject = m.getSubject(); if ("repeat".equals(subject)) { int count = (Integer) m.getData(); if (count > 0) { m = new DefaultMessage("repeat", count - 1); String toName = "actor"+ ???; Actor to = actorTest.getTestActors().get(toName) getManager().send(m, this, to); }

TestActor (cont)  Process init message  Send count messages to random actors with random delays  Process other messages  Typically signal error or delegate to superclass } else if ("init".equals(subject)) { int count = (Integer) m.getData(); for (int i = 0; i < count; i++) { m = new DefaultMessage("repeat", count); String toName = "actor“ + ???; Actor to = actorTest.getTestActors().get(toName); getManager().send(m, this, to); DefaultMessage dm = new DefaultMessage("repeat", count); dm.setDelayUntil(new Date().getTime() + ???); getManager().send(dm, this, this.getClass().getSimpleName()); } } else { … } }

Example Main  Access an actor manager  Create some actors in the common category  Create some actors in the default category  Start all the actors  Keep main alive to allow actors to run  Terminate actor processing DefaultActorManager am = DefaultActorManager.getDefaultInstance(); : Map testActors = new HashMap (); for (int i = 0; i < 2; i++) { Actor a = am.createActor(TestActor.class, "common" + i); a.setCategory("common"); testActors.put(a.getName(), a); } for (int i = 0; i < 5; i++) { Actor a = am.createActor(TestActor.class, "actor" + i); testActors.put(a.getName(), a); } for (String key : testActors.keySet()) { am.startActor(testActors.get(key)); } for (int i = 120; i > 0; i--) { if (i < 10 || i % 10 == 0) System.out.printf("main waiting: %d...%n", i); delay(1000); } : am.terminateAndWait();

Visualize running Actors  GUI shows any activity  Controls at top select example and control execution  Green bar shows active threads  Circle shows active actors and messages between them  Small squares show active threads  Lines show messages  Bottom circles show recent history  Right pane show log trace

Demo  No Example Selected  Countdown started  Most Busy  Staring to slow down  Slowing more  Near done  Done

Online Video of Demo

Questions