Code Monkey home page Code Monkey logo

jv-multithreading-thread-pool's Introduction

Thread pool

Create in main() method an ExecutorService instance with a fixed-sized thread pool for 5 threads. Then add 20 threads of type MyThread to your ExecutorService. Let's add Future objects that we receive to the futures list.

Your threads should return a String in the following format: Task duration was 200 ms, execution finished at 11:27:47.243785

Task duration means that your thread should actually be suspended for this period. You can randomly generate task duration for each thread and use LocalTime.now() to get the time when this thread finishes execution.

After all your tasks are executed, in main() method log the result string from each Future in futures list.

Note that you should push the file with logs to your PR, so please, do not add it to .gitignore. You may probably need to use the absolute path to the log file in log4j2.xml.

Logs example:

INFO core.basesyntax.Main:24 Task duration was 200 ms, execution finished at 11:27:47.243785
INFO core.basesyntax.Main:24 Task duration was 100 ms, execution finished at 11:27:47.358773
INFO core.basesyntax.Main:24 Task duration was 200 ms, execution finished at 11:27:47.562603
INFO core.basesyntax.Main:24 Task duration was 300 ms, execution finished at 11:27:47.865479
INFO core.basesyntax.Main:24 Task duration was 500 ms, execution finished at 11:27:48.367833
INFO core.basesyntax.Main:24 Task duration was 100 ms, execution finished at 11:27:48.470337
INFO core.basesyntax.Main:24 Task duration was 100 ms, execution finished at 11:27:48.574946
INFO core.basesyntax.Main:24 Task duration was 100 ms, execution finished at 11:27:48.677488
INFO core.basesyntax.Main:24 Task duration was 500 ms, execution finished at 11:27:49.181528
INFO core.basesyntax.Main:24 Task duration was 200 ms, execution finished at 11:27:49.391357
INFO core.basesyntax.Main:24 Task duration was 400 ms, execution finished at 11:27:49.796201
INFO core.basesyntax.Main:24 Task duration was 400 ms, execution finished at 11:27:50.197847
INFO core.basesyntax.Main:24 Task duration was 300 ms, execution finished at 11:27:50.500033
INFO core.basesyntax.Main:24 Task duration was 400 ms, execution finished at 11:27:50.901827
INFO core.basesyntax.Main:24 Task duration was 400 ms, execution finished at 11:27:51.303852
INFO core.basesyntax.Main:24 Task duration was 500 ms, execution finished at 11:27:51.807451
INFO core.basesyntax.Main:24 Task duration was 500 ms, execution finished at 11:27:52.310309
INFO core.basesyntax.Main:24 Task duration was 100 ms, execution finished at 11:27:52.412642
INFO core.basesyntax.Main:24 Task duration was 100 ms, execution finished at 11:27:52.519061
INFO core.basesyntax.Main:24 Task duration was 200 ms, execution finished at 11:27:52.722007

jv-multithreading-thread-pool's People

Contributors

kseniiamakarova avatar resci avatar alexrozv avatar

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.