小编rob*_*bin的帖子

非法监控状态两个踏板等待时出现异常

HI编写了一个示例程序,用于测试java中的wait行为.

我的Runnable实现:

class ThreadWait implements Runnable {
    Object lock = new Object();
    ThreadWait(Object lock){
        this.lock = lock;
    }
    @Override
    public void run() {
        try {
            synchronized (lock){
                System.out.println("Started : "+Thread.currentThread().getName());
                wait();
                System.out.println("Completed : "+Thread.currentThread().getName());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的main喜欢中使用:

Object lock = new Object();
ThreadWait t1 = new ThreadWait(lock);
ThreadWait t2 = new ThreadWait(lock);
Thread a= new Thread(t1);
a.setName("A");
Thread b= new Thread(t2);
b.setName("B");
a.start();
b.start();
Run Code Online (Sandbox Code Playgroud)

运行此程序时,我收到此异常:

Exception in thread "A" Exception …
Run Code Online (Sandbox Code Playgroud)

java multithreading illegalmonitorstateexcep

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

GitPython 无法从 Git 导入 Repo

我在文件 git.py 中有一个像下面这样的 python 脚本

#!/usr/bin/env python
# -*- coding:utf-8 -*-

from git import  Repo

git_path = "test"

repo = Repo(git_path)

assert not repo.bare
Run Code Online (Sandbox Code Playgroud)

Python 版本是:Python 2.7.12

操作系统:描述:Ubuntu 16.04.1 LTS

Gitpython - 2.1.7

当我运行 python git.py 时出现以下错误

Traceback (most recent call last):
  File "git.py", line 4, in <module>
    from git import  Repo
  File "/home/user/demo_files/git.py", line 4, in <module>
    from git import  Repo
ImportError: cannot import name Repo
Run Code Online (Sandbox Code Playgroud)

我已经检查了大部分链接,但无法解决我的问题。请帮我。

python git

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

为什么在实践中插入排序比冒泡排序和堆排序更快?

我在链接(http://bigocheatsheet.com/)中看到,插入排序的复杂性与冒泡排序相同,并且堆排序也比这两者更好.但是当我创建一个示例程序并比较插入排序时间令人难以置信时.

类用于测试排序算法.

public class TestSorts {

    public static void main(String[] args) {
        System.out.println("starting");
        Calendar startInstance = null;
        Calendar endInstance = null;

        //Getting the array to sort
        startInstance= Calendar.getInstance();
        //int[] arrayToSort = ArrayClass.getArray(1000);
        int[] arrayToSort = ArrayClass.getWorstArray(10000000);
        endInstance= Calendar.getInstance();
        long timeTakenToGetArray = endInstance.getTimeInMillis()- startInstance.getTimeInMillis();
        System.out.println("StartTime : "+startInstance.getTimeInMillis());
        System.out.println("EndTime : "+endInstance.getTimeInMillis());
        System.out.println("TimeTakenToGetArray : "+timeTakenToGetArray);

        //Bubble Sort       
        startInstance= Calendar.getInstance();
        int[] bubbleSorted = BubbleSort.sort(arrayToSort);
        endInstance= Calendar.getInstance();
        long timeTakenBubble = endInstance.getTimeInMillis() - startInstance.getTimeInMillis();
        System.out.println("StartTime : "+startInstance.getTimeInMillis());
        System.out.println("EndTime : "+endInstance.getTimeInMillis());
        System.out.println("Bubble : "+timeTakenBubble);

        //InsertionSort …
Run Code Online (Sandbox Code Playgroud)

java sorting algorithm

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

我的var变得未定义的问题

我试图在javascript中为String类型创建一个反向函数.我的代码就像

String.prototype.reverse = function () {
    var s = "";
    for(var i=this.length;i>=0;i--){
            s+=this[i];
    }
    return s;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用它时,例如 "test".reverse();

而不是给"tset"它给"undefinedtset"

我正在设置变量var s = ""; 在函数内部,仍未定义即将到来.为什么会这样?

javascript

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