Example usage for java.lang Thread dumpStack

List of usage examples for java.lang Thread dumpStack

Introduction

In this page you can find the example usage for java.lang Thread dumpStack.

Prototype

public static void dumpStack() 

Source Link

Document

Prints a stack trace of the current thread to the standard error stream.

Usage

From source file:net.sf.jabref.logic.layout.Layout.java

public Layout(List<StringInt> parsedEntries, JabRefPreferences prefs,
        JournalAbbreviationLoader repositoryLoader) {
    List<LayoutEntry> tmpEntries = new ArrayList<>(parsedEntries.size());

    List<StringInt> blockEntries = null;
    LayoutEntry le;/*  w  w w.j a  v  a 2 s .  c  o  m*/
    String blockStart = null;

    for (StringInt parsedEntry : parsedEntries) {
        switch (parsedEntry.i) {
        case LayoutHelper.IS_LAYOUT_TEXT:
        case LayoutHelper.IS_SIMPLE_FIELD:
        case LayoutHelper.IS_OPTION_FIELD:
            // Do nothing
            break;
        case LayoutHelper.IS_FIELD_START:
        case LayoutHelper.IS_GROUP_START:
            blockEntries = new ArrayList<>();
            blockStart = parsedEntry.s;
            break;
        case LayoutHelper.IS_FIELD_END:
        case LayoutHelper.IS_GROUP_END:
            if ((blockStart != null) && (blockEntries != null)) {
                if (blockStart.equals(parsedEntry.s)) {
                    blockEntries.add(parsedEntry);
                    le = new LayoutEntry(blockEntries,
                            parsedEntry.i == LayoutHelper.IS_FIELD_END ? LayoutHelper.IS_FIELD_START
                                    : LayoutHelper.IS_GROUP_START,
                            prefs, repositoryLoader);
                    tmpEntries.add(le);
                    blockEntries = null;
                } else {
                    LOGGER.debug(blockStart + '\n' + parsedEntry.s);
                    LOGGER.warn("Nested field/group entries are not implemented!");
                    Thread.dumpStack();
                }
            }
            break;
        default:
            break;
        }

        if (blockEntries == null) {
            tmpEntries.add(new LayoutEntry(parsedEntry, prefs, repositoryLoader));
        } else {
            blockEntries.add(parsedEntry);
        }
    }

    layoutEntries = new ArrayList<>(tmpEntries);

    for (LayoutEntry layoutEntry : layoutEntries) {
        missingFormatters.addAll(layoutEntry.getInvalidFormatters());
    }
}

From source file:TimeResolution.java

/**
 * This method is like the measureSleep() method above, only for the
 * wait() method instead of sleep().//from  w  w w  .j a  v a  2s.  c o  m
 */
private synchronized void measureWait() {
    System.out.printf("                                measured\n");
    System.out.printf("wait time   iterations   total time   per-wait\n");
    for (int sleepTime = 1; sleepTime <= 20; ++sleepTime) {
        int iterations = (sleepTime == 0) ? 10000 : (1000 / sleepTime);
        long startTime = System.nanoTime();
        for (int i = 0; i < iterations; ++i) {
            try {
                wait(sleepTime);
            } catch (Exception e) {
                System.out.println("Exception: " + e);
                Thread.dumpStack();
            }
        }
        long endTime = System.nanoTime();
        long totalTime = (endTime - startTime) / 1000000;
        float calculatedSleepTime = totalTime / (float) iterations;
        System.out.printf("  %2d          %5d         %4d       %5.2f\n", sleepTime, iterations, totalTime,
                calculatedSleepTime);
    }
}

From source file:cn.annoreg.mc.s11n.SerializationManager.java

public NBTBase serialize(Object obj, StorageOption.Option option) {
    if (obj == null) { //Allow to pass over null instances.
        NBTTagCompound tag = new NBTTagCompound();
        tag.setBoolean("__isNull__", true);
        return tag;
    }//w  w  w  .ja  v a  2s  .c o  m
    Class clazz = obj.getClass();
    DataSerializer d = getDataSerializer(clazz);
    InstanceSerializer i = getInstanceSerializer(clazz);
    NBTTagCompound ret = new NBTTagCompound();
    ret.setString("class", clazz.getName());
    ret.setInteger("option", option.ordinal());
    switch (option) {
    case NULL:
        return ret;
    case DATA:
        try {
            if (d == null) {
                if (obj instanceof Collection) {
                    Collection coll = (Collection) obj;
                    NBTTagList list = new NBTTagList();
                    for (Object element : coll) {
                        list.appendTag(serialize(element, StorageOption.Option.DATA));
                    }
                    ret.setBoolean("__isCollection__", true);
                    ret.setTag("collection", list);
                    return ret;
                } else {
                    throw new RuntimeException("Serializer not found.");
                }
            }

            ret.setTag("data", d.writeData(obj));
            return ret;
        } catch (Exception e) {
            ARModContainer.log.error("Failed in data serialization. Class: {}.", clazz.getCanonicalName());
            e.printStackTrace();
            return null;
        }
    case INSTANCE:
    case NULLABLE_INSTANCE:
        try {
            if (i == null) {
                if (obj instanceof Collection) {
                    Collection coll = (Collection) obj;
                    NBTTagList list = new NBTTagList();
                    for (Object element : coll) {
                        list.appendTag(serialize(element, StorageOption.Option.INSTANCE));
                    }
                    ret.setBoolean("__isCollection__", true);
                    ret.setTag("collection", list);
                    return ret;
                } else {
                    throw new RuntimeException("Serializer not found.");
                }
            }

            ret.setTag("instance", i.writeInstance(obj));
            //we need to remember the class of i (also the id of i), not of obj.
            ret.setString("class", i.getClass().getName());
            return ret;
        } catch (Exception e) {
            ARModContainer.log.error("Failed in instance serialization. Class: {}, Object: {}",
                    clazz.getCanonicalName(), obj.toString());
            e.printStackTrace();
            return null;
        }
    case UPDATE:
        try {
            if (i == null || d == null) {
                throw new RuntimeException("Serializer not found.");
            }
            ret.setTag("instance", i.writeInstance(obj));
            ret.setTag("data", d.writeData(obj));
            return ret;
        } catch (Exception e) {
            ARModContainer.log.error("Failed in update serialization. Class: {}.", clazz.getCanonicalName());
            e.printStackTrace();
            return null;
        }
    default:
        ARModContainer.log.error("Failed in serialization. Class: {}. Unknown option.",
                clazz.getCanonicalName());
        Thread.dumpStack();
        return null;
    }
}

From source file:kilim.Task.java

public static void errNotWoven() {
    log.error("############################################################");
    log.error("Task has either not been woven or the classpath is incorrect");
    log.error("############################################################");
    Thread.dumpStack();
    System.exit(0);//  w w  w.j  a  v  a  2 s  .  c o m
}

From source file:kilim.Task.java

public static void errNotWoven(Task t) {
    log.error("############################################################");
    log.error("Task " + t.getClass() + " has either not been woven or the classpath is incorrect");
    log.error("############################################################");
    Thread.dumpStack();
    System.exit(0);/*from w w w. j ava2  s  .  c om*/
}

From source file:hu.mta.sztaki.lpds.cloud.entice.imageoptimizer.iaashandler.amazontarget.EC2VirtualMachine.java

@Override
// invoked from constructor
protected String runInstance(String keyName) throws VMManagementException {
    try {//from w w  w.j av a2s.c o m
        Shrinker.myLogger
                .info("Trying to start instance (" + getImageId() + "/" + instanceType + "@" + endpoint + ")");
        int requests = reqCounter.incrementAndGet();
        //         System.out.println("[T" + (Thread.currentThread().getId() % 100) + "] VMs up: " + requests);
        if (requests > totalReqLimit) {
            Shrinker.myLogger.severe("Terminating shrinking process, too many non-terminated requests");
            Thread.dumpStack();
            System.exit(1);
        }

        RunInstancesRequest runInstancesRequest = new RunInstancesRequest();
        runInstancesRequest.withImageId(getImageId()).withInstanceType(instanceType).withMinCount(1)
                .withMaxCount(1);
        if (keyName != null)
            runInstancesRequest.withKeyName(keyName);
        RunInstancesResult runInstancesResult = this.amazonEC2Client.runInstances(runInstancesRequest);
        this.reservation = runInstancesResult.getReservation();

        List<String> instanceIds = getInstanceIds();
        if (instanceIds.size() != 1)
            throw new Exception("No or too many instances started");
        Shrinker.myLogger.info("Started instance (" + getImageId() + "/" + instanceType + "@" + endpoint + "): "
                + getInstanceIds());

        VirtualMachine.vmsStarted.incrementAndGet();

        this.ip = null;
        this.setPrivateIP(null);
        System.out.println("[T" + (Thread.currentThread().getId() % 100) + "] VM started: " + instanceIds.get(0)
                + " (@" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + ")");
        return instanceIds.get(0);
    } catch (AmazonServiceException x) {
        Shrinker.myLogger.info("runInstance error: " + x.getMessage());
        throw new VMManagementException("runInstance exception", x);
    } catch (AmazonClientException x) {
        Shrinker.myLogger.info("runInstance error: " + x.getMessage());
        throw new VMManagementException("runInstance exception", x);
    } catch (Exception x) {
        Shrinker.myLogger.info("runInstance error: " + x.getMessage());
        throw new VMManagementException("runInstance exception", x);
    }
}

From source file:cn.annoreg.mc.s11n.SerializationManager.java

public Object deserialize(Object obj, NBTBase nbt, StorageOption.Option option) {
    NBTTagCompound tag = (NBTTagCompound) nbt;
    Class<?> clazz = null;//w w w  .  j ava 2s .  co m

    if (tag.getBoolean("__isNull__")) {
        return null;
    }
    if (tag.getBoolean("__isCollection__")) {
        //create the container
        try {
            clazz = Class.forName(tag.getString("class"));
            Collection coll = (Collection) clazz.newInstance();
            NBTTagList nbtcoll = (NBTTagList) tag.getTag("collection");
            for (int i = 0; i < nbtcoll.tagCount(); ++i) {
                Object o = deserialize(null, nbtcoll.getCompoundTagAt(i), option);
                if (o != null)
                    coll.add(o);
            }
            return coll;
        } catch (Exception e) {
            ARModContainer.log.error("Failed in deserialization. Class: {}.", tag.getString("class"));
            e.printStackTrace();
            return null;
        }
    }

    if (option == StorageOption.Option.AUTO) {
        option = StorageOption.Option.values()[tag.getInteger("option")];
    }
    if (tag.getInteger("option") != option.ordinal()) {
        ARModContainer.log.error("Failed in deserialization. Class: {}.", tag.getString("class"));
        Thread.dumpStack();
    }
    NBTBase data = tag.getTag("data");
    NBTBase ins = tag.getTag("instance");
    switch (option) {
    case NULL:
        return null;
    case DATA: {
        try {
            clazz = Class.forName(tag.getString("class"));
        } catch (ClassNotFoundException e) {
            ARModContainer.log.error("Failed in deserialization. Class: {}.", tag.getString("class"));
            e.printStackTrace();
            return null;
        }
        DataSerializer ser = getDataSerializer(clazz);
        try {
            return ser.readData(data, obj);
        } catch (Exception e) {
            ARModContainer.log.error("Failed in data deserialization. Class: {}.", tag.getString("class"));
            e.printStackTrace();
            return null;
        }
    }
    case INSTANCE: {
        InstanceSerializer ser = instanceSerializersFromId.get(tag.getString("class"));
        try {
            if (ser == null)
                throw new RuntimeException(
                        "Can not find instance serializer with id " + tag.getString("class"));
            Object ret = ser.readInstance(ins);
            if (ret == null) {
                throw new NullInstanceException();
            }
            return ret;
        } catch (NullInstanceException e) {
            throw e;
        } catch (Exception e) {
            ARModContainer.log.error("Failed in instance deserialization. Class: {}.", tag.getString("class"));
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    case NULLABLE_INSTANCE: {
        InstanceSerializer ser = instanceSerializersFromId.get(tag.getString("class"));
        try {
            if (ser == null)
                throw new RuntimeException(
                        "Can not find instance serializer with id " + tag.getString("class"));
            return ser.readInstance(ins);
        } catch (Exception e) {
            ARModContainer.log.error("Failed in instance deserialization. Class: {}.", tag.getString("class"));
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    case UPDATE: {
        InstanceSerializer i = instanceSerializersFromId.get(tag.getString("class"));
        try {
            Object objIns = i.readInstance(ins);
            if (objIns == null) {
                throw new Exception("Instance is null.");
            }
            DataSerializer d = getDataSerializer(objIns.getClass());
            d.readData(data, objIns);
            return objIns;
        } catch (Exception e) {
            ARModContainer.log.error("Failed in update deserialization. Class: {}.", tag.getString("class"));
            e.printStackTrace();
            return null;
        }
    }
    default:
        ARModContainer.log.error("Failed in deserialization. Class: {}. Unknown option.",
                tag.getString("class"));
        Thread.dumpStack();
        return null;
    }
}

From source file:net.sf.firemox.xml.XmlTbs.java

/**
 * Returns the referenced attachment declared within the rules definition.
 * //from ww w . ja v  a2  s.c  o m
 * @param attachmentName
 *          the attachment name
 * @return the attachment referenced by the given attachment name as a xml
 *         node
 */
public static XmlParser.Node getReferencedAttachment(String attachmentName) {
    if (attachmentName == null) {
        XmlConfiguration.error("attachment reference name missing = 'null'");
        Thread.dumpStack();
    } else {
        if (Tbs.referencedAttachments != null && Tbs.referencedAttachments.get(attachmentName) != null) {
            return Tbs.referencedAttachments.get(attachmentName);
        }
        XmlConfiguration.error("Could not find referenced attachment '" + attachmentName + "'");
    }
    return null;
}

From source file:net.sf.firemox.xml.XmlTbs.java

/**
 * Returns the referenced action(s). First search into the declared action(s)
 * within the current card, then within the declared action(s) within the
 * rules definition./*from ww w  .j av a2 s.c om*/
 * 
 * @param actionName
 *          the action name
 * @return the action(s) referenced by the given action name as a list
 */
public static List<Node> getReferencedActions(String actionName) {
    if (actionName == null) {
        XmlConfiguration.error("action reference name missing = 'null'");
        Thread.dumpStack();
    } else {
        if (XmlTbs.referencedActions != null && XmlTbs.referencedActions.get(actionName) != null) {
            return XmlTbs.referencedActions.get(actionName);
        }
        if (Tbs.referencedActions != null && Tbs.referencedActions.get(actionName) != null) {
            return Tbs.referencedActions.get(actionName);
        }
        XmlConfiguration.error("Could not find referenced action '" + actionName + "'");
    }
    return new ArrayList<Node>();
}

From source file:hu.mta.sztaki.lpds.cloud.entice.imageoptimizer.iaashandler.amazontarget.EC2VirtualMachine.java

@Override
protected void terminateInstance() throws VMManagementException {
    try {//from   www  .java2s .c  o  m
        int requests = reqCounter.decrementAndGet();
        if (requests < 0) {
            Shrinker.myLogger.severe("Terminating shrinking process, too much VM termination requests");
            Thread.dumpStack();
        }

        Shrinker.myLogger.info("Instance " + getInstanceId() + " received a terminate request");
        TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest();
        terminateInstancesRequest.withInstanceIds(getInstanceIds());
        TerminateInstancesResult res = this.amazonEC2Client.terminateInstances(terminateInstancesRequest);
        Shrinker.myLogger.info("Terminate request dispatched for instance " + getInstanceId());

        List<InstanceStateChange> stateChanges = res.getTerminatingInstances();
        InstanceStateChange state = null;
        for (InstanceStateChange stateChange : stateChanges)
            if (getInstanceId().contains(stateChange.getInstanceId()))
                state = stateChange;
        if (state != null)
            Shrinker.myLogger.info("State of instance " + getInstanceId() + ": "
                    + state.getPreviousState().getName() + " -> " + state.getCurrentState().getName());
        else
            Shrinker.myLogger.info("null state for instance " + getInstanceId());

        // re-send terminate
        if (state == null || !TERMINATED_STATE.equals(state.getCurrentState().getName())) {
            int timeout = 0;
            int counter = 1;
            while (timeout < TERMINATE_TIMEOUT) {
                try {
                    Thread.sleep(5000);
                } catch (Exception x) {
                }
                Shrinker.myLogger.info("Re-sending (" + counter
                        + "x) terminate request dispatched for instance " + getInstanceId());
                try {
                    res = this.amazonEC2Client.terminateInstances(terminateInstancesRequest);
                    stateChanges = res.getTerminatingInstances();
                    for (InstanceStateChange stateChange : stateChanges)
                        if (getInstanceId().contains(stateChange.getInstanceId()))
                            state = stateChange;
                    if (state != null)
                        Shrinker.myLogger.info("State of instance " + getInstanceId() + ": "
                                + state.getPreviousState().getName() + " -> "
                                + state.getCurrentState().getName());
                    else
                        Shrinker.myLogger.info("null state for instance " + getInstanceId());
                } catch (AmazonServiceException x) { // terminated correctly
                    // it can happen that terminate seemingly didn't succeed for the first time (remains running), 
                    // but then the instance id is gone (correctly) so re-sending terminate will cause exception
                    if ("InvalidInstanceID.NotFound".equals(x.getErrorCode()))
                        break;
                    else
                        throw x;
                }
                if (state != null && TERMINATED_STATE.equals(state.getCurrentState().getName()))
                    break;
                timeout += 5000; // repeat every 5 second
                counter++;
            }

            if (timeout >= TERMINATE_TIMEOUT) {
                Shrinker.myLogger.info("ERROR: Cannot terminate instance: " + getInstanceId());
                System.exit(1);
            }
        }

    } catch (AmazonServiceException x) {
        Shrinker.myLogger.info("terminateInstance error: " + x.getMessage());
        throw new VMManagementException("terminateInstance exception", x);
    } catch (AmazonClientException x) {
        Shrinker.myLogger.info("terminateInstance error: " + x.getMessage());
        throw new VMManagementException("terminateInstance exception", x);
    }
    System.out.println("[T" + (Thread.currentThread().getId() % 100) + "] VM terminated: " + getInstanceId()
            + " " + this.ip + " (@" + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())
            + ")");
}