小编Mat*_*uti的帖子

Java先发制人吗?

我已经看到了很多这个问题的答案,但我仍然不确定.

其中之一是"Java是先发制人".(JVM使用抢占式,基于优先级的调度算法(通常是循环算法)进行调度.

第二个是如果两个具有相同优先级的线程运行Java将不会抢占,一个线程可能会饿死.

所以现在我编写了一个程序来检查它,我创建了10个具有最小优先级的线程,然后是10个具有最高优先级的线程,结果是我在所有线程之间跳转 - 这意味着即使两个线程具有相同的优先级,Java也是先发制人的优先

 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @
 */
public class JavaApplication1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        for (int i=0;i<10;i++){
            Thread t=new Thread(new Dog(i));
            t.setPriority(Thread.MIN_PRIORITY);
            t.start();
        }

        try {
            Thread.sleep(5000);
        } catch (InterruptedException ex) {
            Logger.getLogger(JavaApplication1.class.getName()).log(Level.SEVERE, null, ex);
        }
        for (int i …
Run Code Online (Sandbox Code Playgroud)

java multithreading preemptive thread-priority

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

将希伯来字符插入MySQL表时获取问号

我正在使用Netbeans使用Java来构建Web应用程序,JSP使用希伯来字段处理数据库.

DDL如下:

String cityTable = "CREATE TABLE IF NOT EXISTS hebrew_test.table ("
                            +"id int(11) NOT NULL AUTO_INCREMENT,"
                            +"en varchar(30) NOT NULL,"
                            +"he varchar(30) COLLATE utf8_bin NOT NULL,"
                            +"PRIMARY KEY (id)"
                            +") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;";
String insert = "INSERT INTO hebrew_test.table (en, he) VALUES ('A','a')";
String insert2 = "INSERT INTO hebrew_test.table (en, he) VALUES ('B','?')";
String insert3 = "INSERT INTO hebrew_test.table (en, he) VALUES ('C','???')";


executeSQLCommand(cityTable);
executeSQLCommand(insert);
executeSQLCommand(insert2);
executeSQLCommand(insert3);
Run Code Online (Sandbox Code Playgroud)

我得到的输出表:

1   A   a
2   B   ?
3   C   ??? …
Run Code Online (Sandbox Code Playgroud)

java mysql jsp jdbc hebrew

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

为什么我使用?:条件运算符不正确?

我在尝试编译时遇到编译错误,"不是声明",代码是:

(checkDatabaseExist())?connectToDB() : buildDB();
Run Code Online (Sandbox Code Playgroud)

当功能是:

private boolean checkDatabaseExist() {...}
private void connectToDB(){...}
private void buildDB(){...}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

java

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

标签 统计

java ×3

hebrew ×1

jdbc ×1

jsp ×1

multithreading ×1

mysql ×1

preemptive ×1

thread-priority ×1