This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig20; | |
| public class Main { | |
| public static void main(String[] args) throws InterruptedException { | |
| InventoryCounter inventoryCounter =new InventoryCounter(); | |
| IncrementingThread incrementingThread=new IncrementingThread(inventoryCounter); | |
| DecrementingThread decrementingThread=new DecrementingThread(inventoryCounter); | |
| incrementingThread.start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SimpleCountDownLatch { | |
| private int count; | |
| public SimpleCountDownLatch(int count) { | |
| this.count = count; | |
| if (count < 0) { | |
| throw new IllegalArgumentException("count cannot be negative"); | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig19; | |
| //這是編碼練習的自己的解答 | |
| public class SimpleCountDownLatch_solu { | |
| private int count; | |
| public SimpleCountDownLatch_solu(int count) { | |
| this.count = count; | |
| if (count < 0) { | |
| throw new IllegalArgumentException("count cannot be negative"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig19; | |
| //這是編碼練習的題目 | |
| public class SimpleCountDownLatch { | |
| private int count; | |
| public SimpleCountDownLatch(int count) { | |
| this.count = count; | |
| if (count < 0) { | |
| throw new IllegalArgumentException("count cannot be negative"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * MIT License | |
| * | |
| * Copyright (c) 2019 Michael Pogrebinsky | |
| * | |
| * Permission is hereby granted, free of charge, to any person obtaining a copy | |
| * of this software and associated documentation files (the "Software"), to deal | |
| * in the Software without restriction, including without limitation the rights | |
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| * copies of the Software, and to permit persons to whom the Software is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * MIT License | |
| * | |
| * Copyright (c) 2019 Michael Pogrebinsky | |
| * | |
| * Permission is hereby granted, free of charge, to any person obtaining a copy | |
| * of this software and associated documentation files (the "Software"), to deal | |
| * in the Software without restriction, including without limitation the rights | |
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| * copies of the Software, and to permit persons to whom the Software is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig18; | |
| import java.io.File; | |
| import java.io.FileWriter; | |
| import java.io.IOException; | |
| import java.util.Random; | |
| import java.util.StringJoiner; | |
| /** | |
| * Objects as Condition Variables - Wait(), Notify() and NotifyAll() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig18; | |
| import java.util.LinkedList; | |
| import java.util.Queue; | |
| import java.util.concurrent.locks.Condition; | |
| import java.util.concurrent.locks.Lock; | |
| import java.util.concurrent.locks.ReentrantLock; | |
| public class Main { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig17; | |
| import java.util.*; | |
| import java.util.concurrent.locks.Lock; | |
| import java.util.concurrent.locks.ReentrantLock; | |
| import java.util.concurrent.locks.ReentrantReadWriteLock; | |
| /** | |
| * Reentrant Read Write Lock & Database Implementation | |
| * https://www.udemy.com/java-multithreading-concurrency-performance-optimization |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pig17; | |
| import java.util.*; | |
| import java.util.concurrent.locks.Lock; | |
| import java.util.concurrent.locks.ReentrantLock; | |
| import java.util.concurrent.locks.ReentrantReadWriteLock; | |
| /** | |
| * Reentrant Read Write Lock & Database Implementation | |
| * https://www.udemy.com/java-multithreading-concurrency-performance-optimization |