{"id":23034801,"url":"https://github.com/m-thirumal/java-concurrency","last_synced_at":"2025-08-21T11:15:49.207Z","repository":{"id":148987036,"uuid":"282401871","full_name":"m-thirumal/java-concurrency","owner":"m-thirumal","description":"Repository for Learning and quick reference for Java concurrency","archived":false,"fork":false,"pushed_at":"2025-05-17T08:29:49.000Z","size":284,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-17T09:30:09.721Z","etag":null,"topics":["java","multithreading","parallelism"],"latest_commit_sha":null,"homepage":"https://m-thirumal.github.io/java-concurrency/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m-thirumal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-07-25T08:19:27.000Z","updated_at":"2025-05-17T08:29:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"9972d3f6-8640-4aa2-a56d-38527a225ae9","html_url":"https://github.com/m-thirumal/java-concurrency","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/m-thirumal/java-concurrency","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-thirumal%2Fjava-concurrency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-thirumal%2Fjava-concurrency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-thirumal%2Fjava-concurrency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-thirumal%2Fjava-concurrency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m-thirumal","download_url":"https://codeload.github.com/m-thirumal/java-concurrency/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-thirumal%2Fjava-concurrency/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271469227,"owners_count":24765124,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","multithreading","parallelism"],"created_at":"2024-12-15T16:35:49.856Z","updated_at":"2025-08-21T11:15:49.194Z","avatar_url":"https://github.com/m-thirumal.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# java-concurrency\n\n### What is Process?\n\n* A process is a `unit of work` in the Operating System\n* A process is a instance of program loaded in to memory\n* A process can have multiple thread running concurrently/parllel, sharing the same memory and resource of process.\n\n## What is Thread\n\n* A thread is the smallest unit of execution with in the process.\n\n### What is Preemptive \u0026 Non-Preemptive?\n\n**Preemptive** is non-blocking task. \n\n**Non-Preemptive**  is blocking task. \n\n# Concurrency\n\n- Performing multiple task within same time frame but not necessarily executing at the exact same moment.\n\nConcurrency in a CPU is achieved through  `context switching`.\n\n#### How it works\n\n* Context Saving: When CPU switches from one task to another, it saves the current task's state in the memory(Eg: Program counter, registry..)\n* Context Loading: The CPU then loads the context of the next task and continues executing it.\n* Rapid Switching: The CPU repeats this process, switching between tasks so quickly that it seems like they are running simultaneously.\n\n# Parallelism\n\n- Executing multiple task at exact time by utilizing the multiple cores or processors.\n- To achieve parallelism, an application divides its tasks into smaller, independent subtasks. These subtasks are distributed across multiple `CPUs, CPU cores, GPU cores, or similar processing units`, allowing them to be processed in parallel.\n- [Basic Understanding](src/main/java/in/thirumal/parallelism/Definition.md)\n\n```java\nIntStream.range(0, 100).parallel().forEach(i -\u003e {\n        System.out.println(Thread.currentThread().getName() + \" processing number: \" + i);\n       });\n```\n\nOutput:\n```bash\nForkJoinPool.commonPool-worker-6 processing number: 40\nForkJoinPool.commonPool-worker-6 processing number: 41\nForkJoinPool.commonPool-worker-6 processing number: 42\nForkJoinPool.commonPool-worker-2 processing number: 90\nForkJoinPool.commonPool-worker-4 processing number: 15\nmain processing number: 65\nForkJoinPool.commonPool-worker-3 processing number: 56\nForkJoinPool.commonPool-worker-5 processing number: 43\nForkJoinPool.commonPool-worker-6 processing number: 37\nForkJoinPool.commonPool-worker-2 processing number: 91\nForkJoinPool.commonPool-worker-1 processing number: 31\nForkJoinPool.commonPool-worker-4 processing number: 16\nForkJoinPool.commonPool-worker-7 processing number: 6\n......\n```\n\n# Synchronization\n\nSynchronization is the coordination or control of threads to ensure the `consitency` when acessing shared resources.\n\n* `Why it’s needed:`\nIn concurrent/parallel task, shared resources(like variable/data structures) might be accessed or modified by multiple threads. Without `Synchroniztion`, race conditions can occur, leading to the incorrect result.\n\n\n[Synchronize.java](src/main/java/in/thirumal/Synchronize/Synchronize.java ':include :type=code')\n\n\n### Main Concepts\n\n* [Thread Life Cycle](ThreadLifecycle.md)\n* [Basic](src/main/java/in/thirumal/t1basic)\n* [How to decide the number of thread](docs/How%20to%20decide%20number%20of%20threads.md) \n* [Synchronize](src/main/java/in/thirumal/t2Synchronize)\n* [Lock](src/main/java/in/thirumal/t2lock/lock.md)\n* [Pool-Executor](src/main/java/in/thirumal/t2poool)\n* [ThreadLocal](src/main/java/in/thirumal/t1threadlocal)\n* [DeadLock](src/main/java/in/thirumal/t5deadlock)\n* [Seamaphore](src/main/java/in/thirumal/t6semaphore)\n* [Callable \u0026 Future](src/main/java/in/thirumal/t1callablefuture)\n* [Fork Join](src/main/java/in/thirumal/forkjoin)\n* [Complete Future](src/main/java/in/thirumal/t1completablefuture/Basic.md)\n* [Thread safe Data Structure](src/main/java/in/thirumal/t1threadsafedatastructure)\n* [Reactive](src/main/java/in/thirumal/t1reactive)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-thirumal%2Fjava-concurrency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm-thirumal%2Fjava-concurrency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-thirumal%2Fjava-concurrency/lists"}