同步不适用于循环屏障

时间:2015-07-07 22:55:41

标签: java multithreading wait

public class Test {

    final int counter = 0; // it may be a different number
    int add = 0;

    public synchronized void testSync() throws InterruptedException {
        add++;
        if (add == counter) {
            add = 0;

            notifyAll();
        } else {
            while (add > 0) {

                wait();
            }
        }

    }
}

如何修复代码才能使其正常工作?我需要让它成为一个循环障碍。

1 个答案:

答案 0 :(得分:0)

<%=form_for(happening) do |f|%>
   <%=f.text_field :name, class:"updateInput" %>
   <%=f.submit "Save", class:"editButton" %>
   <input type="datetime-local" value="<%= happening.get_html_date %>">
<%end%>

<%= button_to "Delete", happening, method: :delete, class:"editButton"%>