Java 对于重载文件的加载,如何避免加载时间过长

Java 对于重载文件的加载,如何避免加载时间过长,java,multithreading,file,file-io,Java,Multithreading,File,File Io,在我的java代码中,我正在将一个非常沉重的文件加载到GUI。GUI具有播放和暂停按钮,当按下plas时,文件开始加载(8秒)并进行处理,将一些数据发布到网络。当我按pause时,文件停止处理并停止poublishin数据。在暂停之前按play时,文件应开始将数据从上次离开的位置发布到网络 我的问题是,每当我按下“暂停”按钮时按“播放”,文件每次需要8秒才能重新加载。如何避免这种情况 注意: 我正在另一个线程上加载该文件。 文件类型是:很长的逗号分隔文本文件,每行有10个参数 代码:

在我的java代码中,我正在将一个非常沉重的文件加载到
GUI
GUI
具有播放和暂停按钮,当按下plas时,文件开始加载(8秒)并进行处理,将一些数据发布到网络。当我按pause时,文件停止处理并停止poublishin数据。在暂停之前按play时,文件应开始将数据从上次离开的位置发布到网络

我的问题是,每当我按下“暂停”按钮时按“播放”,文件每次需要8秒才能重新加载。如何避免这种情况

注意

我正在另一个线程上加载该文件。 文件类型是:很长的逗号分隔文本文件,每行有10个参数

代码

        protected void loadFile() throws MqttException {
    // TODO Auto-generated method stub
    statusarea.append(Log.d(TAG, "loadFile", "File is loaded") + "\n");
    if (this.LoadFileThread == null) {
        LoadFileThread = new Thread(fileProcessinRunnable, FILE_THREAD);
        LoadFileThread.start();
    }
    /**
     * enable the below else-statement if you want to start a new thread that process the file. enabling it is useless if the play-button is 
     * allowed to be pressed only one time.
     */
    /*else {
        LoadFileThread = new Thread(fileProcessinRunnable, FILE_THREAD);
        LoadFileThread.start();
    }*/
    }
    Runnable fileProcessinRunnable = new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            try {
                processFile(pathToFile(getFilePath()));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };

    private void processFile(File dataFile) throws IOException, InterruptedException {
        // TODO Auto-generated method stub
    if (this.logFile == null) {
        this.logFile = new MeasurementFile(dataFile, MeasurementFile.ENCODING_ISO_8859_1);
        statusarea.append(Log.d(TAG, "processFile", "file finished loading") + "\n");

        if (this.logFileBuffer == null) {
            //the below line of code, assumes that both "this.logFile_IS and this.logFile_BR" are NULL, they are globally declared.
            this.logFileBuffer = this.initFileReader(this.logFile_IS, this.logFile_BR, this.logFile.getFile());
            this.setLogFileBuffer(this.logFileBuffer);
            statusarea.append(Log.w(TAG, "processFile", "logFileBuffer'measurements file' is first initialised.") + "\n");
            setViewEnableState(Bpause, true);
            setViewEnableState(Bstop, true);
        }

@Stefan非常长的文本文件,每行有10个参数,每个参数用逗号分隔。请发布读取文件的线程代码。定义“重”。我根本没有看到任何加载任何文件的代码。