小编Syl*_*wek的帖子

IllegalMonitorStateException notify()和wait()

我有个问题.当我notify()在synchronized块中使用时,我有IllegalMonitorStateException.任何人都可以帮我解决这个问题吗?

我必须这样做,一个线程将发送到第二个线程char,然后这个线程必须等待,第二个线程打印此char.在第二个线程等待之后,第一个再次发送下一个char

Main.java:

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
public class Main extends JFrame {

    Thread t1, t2;
    Consumer con;

    public Main() {
        con = new Consumer();
        startThreads();
    }

    private synchronized void startThreads() {
        t1 = new Thread(new Producent("grudzien", con));
        t1.start();
        t2 = new Thread(con);
        t2.start();
    }

    public class Producent implements Runnable {

        String m_atom;
        char[] atoms; …
Run Code Online (Sandbox Code Playgroud)

java illegalmonitorstateexcep notify wait

6
推荐指数
1
解决办法
2万
查看次数

背景:透明;vs背景:0 0; 差异与威胁

我注意到这background: transparent已变成background: 0 0;使用less。我使用grunt-contrib-less1.4.1是用于"less": "~2.7.1"较少转换为CSS的版本。这些0 0在后台负责什么?使用background: 0 0代替有什么好处background: transparent吗?我试图用谷歌搜索,但是找不到任何可以解释我的东西

css background less

1
推荐指数
1
解决办法
2588
查看次数

链接承诺一个接一个,直到一个返回非空结果

我有一个特定的承诺问题 - 我没有找到任何解决我的问题.

例如,我有服务列表(类)

const services = [
     FirstCacheDataProvider,
     SecondCacheDataProvider,
     // etc, there can be more services, unspecified number of services
];
Run Code Online (Sandbox Code Playgroud)

每个类都实现了返回promise的方法(例如find)(它在此方法中被解析,我无法访问此方法的主体.显然它是异步的)

现在我想逐个调用这个方法直到一个返回NOT EMPTY结果.

有没有办法在没有大链的情况下做到这一点?

工作流程示例:

我们有4项服务

FirstCacheDataProvider.find() // result of promise is empty
SecondCacheDataProvider.find() // result of promise is empty
ThirdCacheDataProvider.find() // result of promise IS NOT EMPTY
// fourth service's method is not called
Run Code Online (Sandbox Code Playgroud)

javascript promise

0
推荐指数
1
解决办法
42
查看次数