Giter VIP home page Giter VIP logo

multi-threaded-timer's Introduction

Multi-threaded Timer

A Java console application with multiple timers

Features

Users can

  • Start timers and give them a Name.
  • Stop a timer by Name.
  • Check a timer by Name or all timers (without a Name ).
  • Starting a timer creates a new thread which increments a counter to keep track of elapsed seconds. Starting an already stopped timer restarts it.

Stopping a timer interrupts the thread created when the timer was started effectively stopping the timer (the counter won't be incremented anymore). Timer threads should check/handle and react accordingly for interrupts while they execute.

Checking a timer prints information about the timer itself: it's name, it's thread ID and the elapsed seconds. Users can check timers that are already stopped.

Requirements

  • Use Threads or Runnables.
  • Use interrupt.
  • Commit your work into a Git repository and submit your repo's URL.

Example Scenario

Command?
start TEA

Command?
check
Name: TEA, ThreadId: 11, Seconds: 1

... after 7 seconds ...

Command?
start COFFEE

Command?
check
Name: TEA, ThreadId: 11, Seconds: 8
Name: COFFEE, ThreadId: 12, Seconds: 1

... after 5 seconds ...

Command?
stop TEA
TEA received interrupt while sleeping

... after 16 seconds ...

Command?
check
Name: TEA, ThreadId: 11, Seconds: 13
Name: COFFEE, ThreadId: 12, Seconds: 22

... after 8 seconds ...

Command?
start TEA

Command?
check
Name: TEA, ThreadId: 13, Seconds: 15
Name: COFFEE, ThreadId: 12, Seconds: 30

... after 4 seconds ...

Command?
exit
Name: TEA, ThreadId: 13, Seconds: 19
Name: COFFEE, ThreadId: 12, Seconds: 34

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.