小编Nea*_*eal的帖子

Java多线程 - 线程优先级

任何人都可以解释线程优先级如何在java中工作.这里的困惑是,如果java不保证Thread根据其优先级的实现,那么为什么这个setpriority()函数用于.

我的代码如下:

public class ThreadSynchronization implements Runnable{

    public synchronized void run() {
        System.out.println("Starting Implementation of Thread "+Thread.currentThread().getName());
        for(int i=0;i<10;i++)
        {
            System.out.println("Thread "+Thread.currentThread().getName()+" value : "+i);
        }
        System.out.println("Ending Implementation of Thread "+Thread.currentThread().getName());
    }

    public static void main(String[] args) {
        System.out.println("Program starts...");
        ThreadSynchronization th1 = new ThreadSynchronization();
        Thread t1 = new Thread(th1);
        t1.setPriority(1);
        synchronized(t1)
        {
            t1.start();
        }

        ThreadSynchronization th2 = new ThreadSynchronization();
        Thread t2 = new Thread(th2);
        t2.setPriority(9);
        synchronized (t2) {
            t2.start(); 
        }

        System.out.println("Program ends...");
    }
}
Run Code Online (Sandbox Code Playgroud)

在上面的程序中,即使我改变优先级,我发现输出没有区别.另外,如何使用线程优先级的实时应用将会有很大帮助.谢谢.

java multithreading thread-priority

11
推荐指数
2
解决办法
7632
查看次数

从数据库中检索数据并使用文本框在表的行中动态显示它

我目前正在开展一个库存管理项目.我在Netbeans平台上使用JSP和MySQL.在我的查询项目中,我需要从数据库中检索值并将其显示在表中.要显示的行在我的页面中应该是动态的.它们应该以任何数字显示.假设当我想根据我选择的特定选项检索值时,我应该能够根据选择显示所有数据并将其显示在表的行中.我无法在表格的多行中显示它,因为我使用文本框来显示值.这是代码片段:

<table>
    <tr>
        <td>
            <select name="choice_type">
            <option>select</option>
            <option value="part_type">part_type</option>
            <option value="category">category</option>
            <option value="names">names</option>
            </select>    
        </td>
    </tr> 
    <tr>
        <th>VAL</th>
        <th>VAL DESC</th>
    </tr>
    <tr>
        <td> <input type="text" name="val"  id="val" size="15" /></td>
        <td> <input type="text" name="val_desc"  id="val_desc" size="15" /></td>
    </tr>
</table>   

<input type="submit" name="Query" value="Query" onClick="getData();"/>
Run Code Online (Sandbox Code Playgroud)

getData()函数如下:

function getData(){ 
    xmlHttp=GetXmlHttpObject()
    var id=document.getElementById("choice_type").value;
    var url="choice_retrieval.jsp";//The code for this file is defined below 
    url=url+"?choice_type="+id;
    xmlHttp.onreadystatechange=stateChanged 
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null);
}

function stateChanged(){ 
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    var showdata = xmlHttp.responseText; 
    var strar = showdata.split(":");
    if(strar.length>1){
    var strname = …
Run Code Online (Sandbox Code Playgroud)

java mysql jsp netbeans

8
推荐指数
1
解决办法
10万
查看次数

C函数到宏

我需要在C中编写宏而不是函数

功能如下:

void FSTATUS(int stat,char msg[])
{
    if(stat != 0)
    {
        EMH_ask_error_text(stat, &msg);
        printf("Error : \"%d\",\"%s\"\n",stat,msg);
    }
    else 
        printf("\n -------- %s -------- \n",msg);
}
Run Code Online (Sandbox Code Playgroud)

因为有很少的例子可用如何在宏中使用if语句,我被困在这部分,我无法弄清楚如何将其转换为宏.任何人都可以帮我解决上面的代码.

方案:

我使用内联函数而不是宏

c macros function

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

标签 统计

java ×2

c ×1

function ×1

jsp ×1

macros ×1

multithreading ×1

mysql ×1

netbeans ×1

thread-priority ×1