How to kill a new thread that is generated in Java?

I have a GUI and I am running another process in a different thread than the gui thread.

I have stop button in the GUI and when I hit the stop button I want to kill this thread.

This is how I start the new thread in the event handler:

else if (toolItem == Gui.item23) {
            final String content = Gui.getFileList();
            Map<Integer, TreeItem> checkListMap = new HashMap<Integer, TreeItem>();
            final Map<Integer, String> checkNameMap1= new HashMap<Integer, String>();
            final Map<Integer, String> checkNameMap = CheckListTree.getInstance().getCheckedStandards(checkListMap, checkNameMap1);
            new Thread(new Runnable() {
                public void run() {
                    try {
                        List<CheckDetail> checkDetails = RunPerl.runMtcheck(content,checkNameMap);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                    } finally {

Open in new window

How can I stop or kill this thread?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick BogersDatacenter platform engineer LindowsCommented:

You would need to know the PID assigned to this thread, not sure how to determine this in Java.
The best (closest) solution would be something like: ManagementFactory.getRuntimeMXBean().getName()  and kill this PID.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The ultimate decider would be a reference of type Process (the Perl process) on which you can call Process.destroy. As it happens, i'm working on this issue at the moment, so watch this space ...
TolgarAuthor Commented:
I am waiting for your reply cehj.

Why not open a socket between the 2 processes, and send a killer token that way?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.