質問 :-
Java を使用して、クリティカル セクションで複数のスレッドを同時に実行できるようにする方法を教えてください。
同期されたキーワードのためにクリティカルセクションにアクセスできるスレッドは1つだけなので、私が行った解決策(以下に示す)は間違っていると感じています。誰でもこれを確認し、可能であれば他の解決策を投稿してください。
私の解決策
package multiplex;
public class Multiplex {
    private static Multiplex multiplex = new Multiplex();
    private volatile static int counter = 0;
    /**
     * @param args
     */
    public static void main(String[] args) {
        Runnable run = new Runnable() {
            @Override
            public void run() {
                try {
                    multiplex.criticalSection();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        };
        for(int index = 0; index < 100; index++){
            Thread thread = new Thread(run);
            thread.setName("Multiplex"+index);
            thread.start();
        }
    }
    public void criticalSection() throws InterruptedException{
        System.out.println("counter is" + counter);
            synchronized (multiplex) {
                    if(counter <=5 ){
                    counter++;
                    System.out.println("No Counter is " + counter);
                    Thread.sleep(1000);
                    System.out.println(Thread.currentThread().getName() + "Hello I am critical");
                    multiplex.notify();
                }else{
                    counter--;
                    System.out.println("Waiting Thread" + Thread.currentThread().getName() + " " + counter);
                    multiplex.wait();
                }
            }
    }
}