小编tru*_*ity的帖子

在Java中并行线程中写入文件的最佳方法是什么?

我有一个执行大量计算的程序,并经常将它们报告给文件.我知道频繁的写操作会使程序运行速度降低很多,所以为了避免它,我希望有一个专门用于写操作的第二个线程.

现在我正在用我写的这个课做这个(不耐烦可以跳到问题的最后):

public class ParallelWriter implements Runnable {

    private File file;
    private BlockingQueue<Item> q;
    private int indentation;

    public ParallelWriter( File f ){
        file = f;
        q = new LinkedBlockingQueue<Item>();
        indentation = 0;
    }

    public ParallelWriter append( CharSequence str ){
        try {
            CharSeqItem item = new CharSeqItem();
            item.content = str;
            item.type = ItemType.CHARSEQ;
            q.put(item);
            return this;
        } catch (InterruptedException ex) {
            throw new RuntimeException( ex );
        }
    }

    public ParallelWriter newLine(){
        try {
            Item item = new Item();
            item.type = ItemType.NEWLINE; …
Run Code Online (Sandbox Code Playgroud)

java multithreading file

24
推荐指数
3
解决办法
2万
查看次数

为什么html表单上的重置按钮不会重置隐藏字段?

我发现了令人惊讶的事情:

<html>
<head>
<script type="text/javascript">
function f()
{
document.getElementById("h").value++;
document.getElementById("x").value++;
}
</script>
</head>
<body>

<form>
<input type="hidden" name="hidden" id="h" value="5"/>
<input type="text" id="x" value="5"/>
<input name='clear' type='reset' id='clear' value='Clear'>
</form>

<button type="button" onclick="f()">Increment</button>
<button type="button" onclick="alert(document.getElementById('h').value)">Show hidden</button>

</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

在Firefox 4.0.1中尝试此操作,单击"清除"始终会将文本输入重置为5,但永远不会重置隐藏字段.

我(和其他人)根本没想到这种行为:我们期望隐藏的值也被重置!

任何人都可以指向解释为什么隐藏输入被重置按钮区别对待的文档或规范?

关于为什么这种行为是可取的解释也是受欢迎的.

html forms reset hidden-field

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

如何使用WEKA API学习贝叶斯网络(结构+参数)?

有没有人知道使用WEKA API从数据中学习贝叶斯网络的"正确"程序?我在WEKA文档中找不到好的说明.

基于文档和每个函数"应该"做什么,我认为这将工作:

Instances ins = DataSource.read( filename );
ins.setClassIndex(0);

K2 learner = new K2();

MultiNomialBMAEstimator estimator = new MultiNomialBMAEstimator();
estimator.setUseK2Prior(true);

EditableBayesNet bn = new EditableBayesNet( ins );
bn.initStructure();

learner.buildStructure(bn, ins);
estimator.estimateCPTs(bn);
Run Code Online (Sandbox Code Playgroud)

但事实并非如此.我已经尝试了这个和其他变化,我一直在WEKA代码中ArrayIndexOutOfBoundsException或者NullPointerException某个地方,所以我错过了什么?

java api bayesian-networks weka

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

Android计时器/ timertask导致我的应用程序崩溃?

只需在mainActivity的onCreate中测试一个简单的代码块:

Timer timer2 = new Timer(); 
        TimerTask testing = new TimerTask() {
            public void run() { 
                Toast.makeText(mainActivity.this, "test", Toast.LENGTH_SHORT).show();

            }
        };
        timer2.schedule(testing, 1000);
Run Code Online (Sandbox Code Playgroud)

我得到了"强制关闭"错误.

是什么赋予了?

java android timer

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

CSS翻转 - 悬停问题?

翻滚时我遇到了一些麻烦......希望你能帮助我!

我正在使用li导航,我希望有单独的框链接到不同的页面.这部分很好,工作得很好.我希望能够将鼠标悬停在方框上并让方框和链接更改颜色.我可以让盒子改变没问题,当你将鼠标悬停在它上面时链接会发生变化,但当你只是悬停在盒子上时,它们是否有一种方法可以改变?这是我到目前为止所得到的:

#nav-menu ul{float: right; text-align: center;}

#nav-menu li{margin-right: 5px; list-style:none; padding-left: 1px; text-align: center; font-size: 14px;float:left; padding:0px 15px; width: 57px; position:relative;z-index:200; background: #000; color: #FFFFFF; font-family: georgia;}

#nav-menu li a{display: block; float: left; color:#fdf2e7;font-size:14px;text-decoration:none; text-align: center; padding:5px 0px 5px 0px; font-family: georgia;}

#nav-menu a:hover{display: block; color:#000000; text-align: center; background: #f3d5e1; text-decoration:none !important; font-family: georgia;}

#nav-menu:hover{display: block; color:#000000; text-align: center; background: #f3d5e1; text-decoration:none !important; font-family: georgia;}
Run Code Online (Sandbox Code Playgroud)

-

任何帮助将不胜感激.谢谢!:)

css rollover colors hover html-lists

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

未终止的语句适用于Java

对于CS类,我必须打印2的所有权力n.我编写了以下代码,其中我故意在循环内的语句末尾省略了分号.为什么这样做?在C++中你会得到一个令人讨厌的错误.您能否提供编译器尝试执行的操作的技术说明?

int n = 100;

int a = 0;
while (Math.pow(2, a++) < n) {
    System.out.println(Math.pow(2, a))
}
Run Code Online (Sandbox Code Playgroud)

发生这种情况的IDE是NetBeans.

NetBeans显示它无法编译(它变为红色),但无论如何它都会运行.有人可以解释一下,使用JVM,为什么会发生这种情况?

java netbeans while-loop

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

哪个 windows.h 标头定义了 NULL?

我必须编写一些Windows代码,并且我想尽可能将其与Linux部分分开。

在某一时刻,我需要检查 Windows 代码中的 NULL,但我不想包含stdio.hor stdlib.h

我强烈怀疑 NULL 是在 中的某处定义的windows.h,但我找不到该页面。我发现了这个,这很有趣,但没有告诉我我想知道什么。

c

-6
推荐指数
1
解决办法
620
查看次数