小编mho*_*r38的帖子

取消文件打开对话框后的InterruptedException - 1.6.0_26

以下代码的输出是:

java.vendor     Sun Microsystems Inc.
java.version    1.6.0_26
java.runtime.version    1.6.0_26-b03
sun.arch.data.model     32
os.name     Windows XP
os.version  5.1
os.arch     x86
Input selection cancelled by user.
Exception while removing reference: java.lang.InterruptedException
java.lang.InterruptedException
    at java.lang.Object.wait(Native Method)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    at java.lang.ref.ReferenceQueue.remove(Unknown Source)
    at sun.java2d.Disposer.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

以下代码显示了我的计算机上的异常.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GUI extends JPanel implements ActionListener {

    private final String newline = System.getProperty("line.separator");
    JButton openButton;
    JTextArea log;
    JFileChooser fc;

    public GUI() {
        super(new BorderLayout());

        log = new JTextArea(20,40); …
Run Code Online (Sandbox Code Playgroud)

java swing jfilechooser interrupted-exception

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

在一段时间内运行代码的更好方法

我需要在预定义的时间内运行一些代码,当时间到了需要停止时.目前我正在使用TimerTask来允许代码执行一段时间,但这会导致代码创建无穷无尽的线程,而这只是效率不高.还有更好的选择吗?

当前代码;

// Calculate the new lines to draw 
            Timer timer3 = new Timer();
            timer3.schedule(new TimerTask(){
                public void run(){
                    ArrayList<String> Coords = new ArrayList<String>();
                    int x = Float.valueOf(lastFour[0]).intValue();
                    int y = Float.valueOf(lastFour[1]).intValue();
                    int x1 = Float.valueOf(lastFour[2]).intValue();
                    int y1 = Float.valueOf(lastFour[3]).intValue();
                    //Could be the wrong way round (x1,y1,x,y)?
                    Coords = CoordFiller.coordFillCalc(x, y, x1, y1);
                    String newCoOrds = "";
                    for (int j = 0; j < Coords.size(); j++)
                    {
                        newCoOrds += Coords.get(j) + " ";
                    }
                    newCoOrds.trim();
                    ClientStorage.storeAmmendedMotion(newCoOrds);

                }

            }
            ,time);
Run Code Online (Sandbox Code Playgroud)

java timertask

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

用Commons CSV解析CSV-引起IOException的引号中的引号

我正在使用Commons CSV解析与电视节目有关的CSV内容。其中一个节目的节目名称带有双引号;

2010年9月10日116,6,2,29,“” JJ“(60分钟)”,“ http://www.tvmaze.com/episodes/4855/criminal-minds-6x02-jj

节目名称为“ JJ”(60分钟),该名称已用双引号引起来。这在封装的令牌和定界符之间抛出IOException java.io.IOException:(第1行)无效的char。

    ArrayList<String> allElements = new ArrayList<String>();
    CSVFormat csvFormat = CSVFormat.DEFAULT;
    CSVParser csvFileParser = new CSVParser(new StringReader(line), csvFormat);

    List<CSVRecord> csvRecords = null;

    csvRecords = csvFileParser.getRecords();

    for (CSVRecord record : csvRecords) {
        int length = record.size();
        for (int x = 0; x < length; x++) {
            allElements.add(record.get(x));
        }
    }

    csvFileParser.close();
    return allElements;
Run Code Online (Sandbox Code Playgroud)

CSVFormat.DEFAULT已设置withQuote('“')

我认为此CSV的格式不正确,应为““ JJ”“(60分钟)”“” JJ“(60分钟)”-但是有没有办法让通用CSV处理此问题,或者我需要手动修复此条目?

附加信息:其他显示名称在CSV条目中包含空格和逗号,并放在双引号中。

java csv double-quotes apache-commons-csv

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

在Java中,如果两个类在同一时刻调用第三个类中的方法会发生什么?

在我的项目中,我有一个由客户端类调用的游戏类.目前,游戏类会写入文件的路径,客户端类将从此文件中读取并清除内容.我在这里访问的冲突太多,所以想要使用另一个类作为存储路径数据的方法.但是,我想知道,如果仍然存在问题,或者如果游戏类试图调用存储类中的方法进行写入,同时客户端类在同一时刻调用存储中的方法,结果会是什么课程阅读和清除.

java methods multithreading contention

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

Java CPU资源占用率100%

我编写了一个程序,当它启动时运行大约96%的CPU,然后在崩溃之前很快将CPU提示为100%.我需要跟踪CPU不断执行的操作,无论是程序运行还是特定方法或调用正在进行.

有什么建议或链接吗?

谢谢.

java cpu-usage

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