简体   繁体   中英

How to terminate a process in java?

if a process is not going to finish means if it getting stucked ... how can i realize it and terminate it.

i am working on a software which processes millions of files and each files takes few seconds to get process, but some files get stucked during processing, i want to **

skip those files.

** how can i do this??

details:

the files are first PARSED ------> then it is converted to .adv files ---------> later into triples .tpl

some files are getting stucked while generating .adv files.

Decide how much time you are willing to spend generating one file before skipping it. You can set a timer with that time limit and check if it's still uploading the same file since the last time it went off. You shouldn't notice that much of a difference in CPU performance with just one timer that performs a simple check.

edit:

fileTimer = new Timer(maxDelay, checkFile);
fileTimer.start();
//set currentFile


ActionListener checkFile = new ActionListener() {
    String lastFile;
    public void actionPerformed(ActionEvent e) {
        if (this.lastFile == currentFile)
            //terminate process
        else
            lastFile = currentFile
    }

}

I'm not quite sure how to terminate the process. I'm not super familiar with multi-threading. Any ideas on that @anshulkatta?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM