This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 68584 - Infinite loops make IDE unresponsive
Summary: Infinite loops make IDE unresponsive
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: PC Windows XP
: P3 blocker (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-12 12:57 UTC by kitfox
Modified: 2007-09-26 09:14 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kitfox 2005-11-12 12:57:39 UTC
The below (incorrect) program enters an infinite loop.  When I run this program,
the IDE becomes unresponsive, and I need to kill NetBeans through the Windows
process manager.



package com.kitfox.util.datastruct;

import java.util.*;

/**
 * A quicksort algorithm that will sort very quickly and without allocating
 * additional memory an array that is already mostly sorted.
 *
 * Will also perform an O(n log n) quicksort on a regular list.
 *
 * http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/quick/quicken.htm
 *
 * @author kitfox
 */
public class Quicksort
{
    
    /** Creates a new instance of Quicksort */
    private Quicksort()
    {
    }
    
    public static <T extends Comparable<? super T>> void quicksort(List<T> list)
    {
        quicksort(list, 0, list.size() - 1);
    }
    
    /**
     * Quicksort elements of this list from lo to hi inclusive
     */
    public static <T extends Comparable<? super T>> void quicksort(List<T> list,
int lo, int hi)
    {
        //  lo is the lower index, hi is the upper index
        //  of the region of array a that is to be sorted
        int i = lo, j = hi;
        T pivot = list.get((lo + hi) / 2);
        
        //  partition
        do
        {
            while (i < hi && list.get(i).compareTo(pivot) <= 0)
            {
                i++;
            }
            while (j > lo && list.get(j).compareTo(pivot) >= 0)
            {
                j--;
            }
            if (i < j)
            {
                T ele1 = list.get(i);
                T ele2 = list.get(j);
                list.set(i, ele2);
                list.set(j, ele1);
                i++; j--;
            }
        } while (i <= j);
        
        //  recursion
        if (lo < j) quicksort(list, lo, j);
        if (i < hi) quicksort(list, i, hi);
    }
    
    public static void main(String[] args)
    {
        Vector<Integer> list = new Vector<Integer>();
//        for (Integer ival: new int[]{1, 5, 3, 9, 6, 0, 23, 7, 2, 3, 6, 7})
        for (Integer ival: new int[]{2, 3, 1})
        {
            list.add(ival);
        }
        
        quicksort(list);
        
        for (Integer ival: list)
        {
            System.err.print(" " + ival);
        }
    }
}
Comment 1 Peter Pis 2005-11-14 15:04:53 UTC
Reassigning to "java" for evaluation.
Comment 2 Pavel Flaska 2005-11-14 15:36:01 UTC
It is neither bug in NetBeans, nor bug in java. When your program running
infinite loop, your process consume system resources. (Bear in mind id does not
run inside the IDE.) It is up to operating system, which process will get cpu
time. -- On Windows, IDE responses really slow. And similiary other processes
running in system. In such case, you still can go to Runtime tab, expand
Processes node and kill the process in infinitive loop from the IDE. You must be
patient because the Windows does not get enough CPU time, so the action are
really slow. (UNIX operating system does not go to these problems and IDE is
responsive enough.)