• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Application locking up

 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I have a problem with my application. Everytime I run it after a minute or so it locks up. I'm not sure what is causing thins - if its too many threads, or what? Could you please give me some suggestions
on how to resolve this,


Thanks,

Ted
 
Ranch Hand
Posts: 91
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ted,

What kind of application are you running ? What does it do ? Can you post the code ?
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Mano pointed out there are too many unknowns are this point especially without any code.

However here are a few stabs in the dark:
  • Many times people have issues with concurrency/mult threaded programming
  • This could be related to only your system e.g. AntiVirus software or firewall
  • Inaccessible or slow resource(s)

  • As you can see, without any code to analyze the problems can range drastically.
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It is a 3D game editor...well its supposed to be. I use a lot of static classes and threads and I think that's part of it but I'm not convinced that's the only problem lurking.


    The main function that initializes all the threads etc... is below:





     
    Marshal
    Posts: 80066
    410
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    How many Threads have you got? Why?
    That code is difficult to read because so much of it is commented out. Please remove the commented out code and the unnecessary whilespace.
     
    Ranch Hand
    Posts: 52
    1
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You can capture JFR of the application, it will shed more light in to which part of code is causing the contention, what are the threaddumps, is there any issues with memory/cpu utilisation etc.
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Here, comment free

     
    Rancher
    Posts: 5076
    38
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Can you add print statements to track where the code is executing?  The print out should show where the execution flow is going and what the values of key variables are as they are used.
    For example if there is a tight loop that is running forever, the print outs inside the loop will go forever.
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    As I thought, this code seems to be the bottleneck. Is there a way I can optimize it?


    MainMerged.java (entry poitn)


    CClock.java



    and Timer Manager


    I'm also getting this exception in Loop.java:



    Loop.java:

     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Is there a way I can write a new line into the output when using printwriter. Can I do a simple
    \n?
     
    Norm Radder
    Rancher
    Posts: 5076
    38
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    As I thought, this code seems to be the bottleneck


    How have you determined that?

    write a new line into the output when using printwriter.


    See the API doc for the PrintWriter class.  It has several methods that will write a new line.
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ok. I'll look up append. Nothing showed up on the intellisense so I assumed (my fault) that there wasn't one.


    As far as the bottleneck goes, when I uncommented that code the game engine worked fine. Well it didn't hang up anyway. As sooon as I uncommented it, it started locking up again. I'm not sure how to fix the problem however.
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    As for PrintWriter, I just looked it up in the API and the writer function doesn't have any newline . I'm looking for something like println. Does that exist on the file side?
     
    Norm Radder
    Rancher
    Posts: 5076
    38
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    What API doc did you look in?  Here are a few lines for the PrintWriter class:


    void println()
    Terminates the current line by writing the line separator string.
    void println(boolean x)
    Prints a boolean value and then terminates the line.
    void println(char x)
    Prints a character and then terminates the line.
    void println(char[] x)
    Prints an array of characters and then terminates the line.
    void println(double x)
    Prints a double-precision floating-point number and then terminates the line.
    void println(float x)
    Prints a floating-point number and then terminates the line.
    void println(int x)
    Prints an integer and then terminates the line.



    when I uncommented that code


    What lines in what class are you talking about?
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    For the above mentioned Main class:

    public class MainMerged {

    // The role of this class is to test out all the
    // programmatic systems before graphics are
    // introduced

    public static MessageManager messageManager = new MessageManager();
    public static SceneGraphManager sceneGraph = new SceneGraphManager();
    public static WebServiceFactory webServiceFactory = new WebServiceFactory();
    public static GameBlackboard gameBlackBoard = new GameBlackboard();
    public static XMLAdapter xmlAdapter = new XMLAdapter();
    public static ObjectManager objManager = new ObjectManager();
    public static ThreadFactory threadFactory;
    public static CEventManager eventManager = new CEventManager();
    public static PublishingManager publishManager = new PublishingManager();
    public static CScheduler scheduler = new CScheduler();
    public static CTaskManager taskManager = new CTaskManager();
    //public static Profiler profiler = new Profiler();
    public static DTIClass dtiClass = new DTIClass("Main", null);

    public static OutputLog log = new OutputLog();

    // UI classes
    public static Inspector ins = new Inspector();
    public static InspectorManager insm = new InspectorManager();
    public static Manager manager = new Manager();
    public static UserInterface ui = new UserInterface();
    public static GameLogic gameLogic = new GameLogic();
    static boolean simulate = false; // set to true to run simulation without rasterization
    static RunThrough runThrough = new RunThrough();
    public static InputHandler inputHandler = new InputHandler();
    public static InputManager inputManager = new InputManager();

    //

    // clock object
    public static CClock clock = new CClock();

    public static CProfiler profiler = new CProfiler();

    public static JournalManager journal = new JournalManager();

    public static Shell shell = new Shell();


    public static void main(String[] args) throws InterruptedException, FileNotFoundException {
    System.out.println("Welcome to NecroTek3D");

    // initialize journaling system
    JournalManager journaling = new JournalManager();
    Thread journalingThread = new Thread(journaling);
    journalingThread.start();

    CJournal.Journal(MainMerged.class, "Testing CJournal");

    JournalManager.beginJournal();

    ////Thread t0 = new Thread(log);
    ////t0.start();


    // Launch Profiler, Journal, and Logging Systems
    Thread m = new Thread(profiler);
    m.start();
    CProfiler.ProfileBegin("Main Merged");

    // Launching Journal
    CJournal.Journal(Main.class, "Launching the Journaling ");

    Thread j = new  Thread(journal);
    j.start();

    //initializing clock system
    ////JournalManager.JournalEntry(MainMerged.class, "main", "Launching clock timer thread");
    ////Thread c = new Thread(clock);
    ////c.start();

    // Initialize scheduling system
    ////CJournal.Journal(Main.class, "Launching the scheduling system");
    ////CTimerManager.init();
    ///CJournal.Journal(Main.class, "Begin Timing. Testing Timer Unit");

    // Initialize a dummy timer
    ////CTimer dummy_timer = CTimerManager.getNewTimer(30, 2);

    // Create a test message

    Message message = new Message();
    message.mflag = EEventMachine.TEST_EVENT_1;

    CJournal.Journal(Main.class, "Testing messaging system " + message.mflag.toString());
    CJournal.Journal(Main.class, "Set message.mflag to " + message.mflag.toString());

    CJournal.Journal(Main.class, "Testing Task Manager");

    CTask task = new CTask();
    task.message = message;

    CJournal.Journal(Main.class, "Set task message to dummy message");

    CJournal.Journal(Main.class, "Testing Scheduler");

    CScheduler.addToSchedule(task);

    CEvent event = new CEvent();

    CJournal.Journal(Main.class, "Testing Event Manager");
    CJournal.Journal(Main.class, "Created dummy CEvent. Pushing to event manager.");

    CEventManager.push_events(event);

    // Initialize memory system

    /*
    * CJournal.Journal(Main.class, "Testing Memory System");
    *
    * CJournal.Journal(Main.class, "Establishing memory pool");
    *
    * objManager.InitPool();
    *
    * CJournal.Journal(Main.class, "Attempting memory request: Dummy string object"
    * );
    *
    * String stringObject = (String) ObjectManager.requestObjectOfClass(String);
    *
    * //System.out.println(stringObject);
    *
    * CJournal.Journal(Main.class,
    * "Attempting integer memory request. Dummy integer objects");
    *
    * Integer intObject = (Integer) ObjectManager.requestObjectOfClass();
    *
    * //test formula
    *
    * int a = 0; int b = 1; int c = intObject.intValue(); c = a + b;
    *
    * CJournal.Journal(Main.class, "Dumy keycode for memory. Value is " + c +
    * "should add to 1");
    *
    */

    // Initialize Thread Pooling Thread System?
    ////threadFactory = Executors.defaultThreadFactory();

    // initialize message manager
    CJournal.Journal(Main.class, "Initializing message manager");
    MessageManager messageManager = new MessageManager();

    messageManager.start();

    // send bootstrap message
    CJournal.Journal(Main.class, "Testing messanger: sending bootstrapping message to messagemanager");
    Message boot_strap_message = new Message();
    boot_strap_message.mflag = EEventMachine.EM_BOOTSTRAP;
    messageManager.EnqueueMessage(boot_strap_message);

    // initializing Scene Graph (need to perform a test, declared above)
    /*
    * CJournal.Journal(Main.class, "Testing Scene Graph"); SceneGraphNode sgn = new
    * SceneGraphNode(); SceneGraphManager.add(sgn, SceneGraphManager.root);
    */
    sceneGraph.start();

    // initialziing inspector (have to rewrite)

    // initializing inspector manager (have to rewrite)

    // initializing user interface (have to rewrite)

    // initializizng web service factory

    CJournal.Journal(Main.class, "Initialzing web service factory...");

    webServiceFactory.start();

    // initializing black board

    CJournal.Journal(Main.class, "Initialzing game black board...");

    gameBlackBoard.start();

    // launching xml reader
    xmlAdapter.adapt("demo.xml");

    // launch xml reader demo

    GameInitializeService.initializeService();

    // !!!upon launching file, use hotloader to load the resources - use
    // XMLSceneLoader to get objects and add to scenegraph
    // load xml hexagon, start spawning position
    // load fringe using hotloader

    // initializing hot loader

    //CJournal.Journal(Main.class, "Initialzing hot loader...");

    /*********Initialize Hot Loader todo***********/
    //CHotLoader.InitHotLoader();

    //GameMapManager.LoadIndices();

    // initailizing input handler (have to rewrite)

    // Dumping Scene Graph Info
    ////CJournal.Journal(Main.class, "Dumping scene graph output (loaded from XMLAdapter)");
    ////SceneGraphManager.output();

    /// starting event manager
    Thread t1 = new Thread(eventManager);
    t1.start();

    // starting scheduler
    Thread t2 = new Thread(scheduler);
    t2.start();

    /// running publish manager
    publishManager.start();

    /// initializing task manager
    taskManager.start();

    // Launch profiler
    // Profiler.ProfileInit();


    CProfiler.ProfileEnd("Main Merged");

    JournalManager.JournalEntry(MainMerged.class, "main", "Preparing Game Loop");

    JournalManager.endJournal();
    JournalManager.JournalToFile();



    // 2. Game Logic Init
    //gameLogic.run();



    // testing main game loop
    ////CJournal.Journal(Main.class, "Testing main game loop");
    ////Loop loop = new Loop(); // hand over to game loop
    ////loop.start();

    ////JournalManager.JournalEntry(MainMerged.class, "main", "Preparing user interface");

    //shell thread


    // runThrough.run();

    // test bloom filter

    TestBloomFilter.testBloomFilter(5, 7, 8);


    //The method below works - don't touch it
    //ui.begin();
    ////MainMerged mainMerged = new MainMerged();
    ////mainMerged.backuprun();

    //CubeObject cube = new CubeObject();
    //CubeObject2 cube2= new CubeObject2();
    //Renderer renderer = new Renderer(true, true);
    //renderer.pushData(cube, cube2);
    ////renderer.copyIntoBuffers(cube);
    //renderer.main(null);


    ////Thread s = new Thread(shell);
    ////s.start();




    return;
    }
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry, I forgot the  code block
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I commented out lines 73 through 84 which seemed to be the bottleneck. There may be others.
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I commented out lines 73 through 84 which seemed to be the bottleneck. There may be others.
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    There is a bottleneck on line 221 too where TaskManager thread is started.
     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    There is a bottleneck on line 221 too where TaskManager thread is started.
    The main slowdown seems to actually be in my game loop:


     
    Ted Gress
    Ranch Hand
    Posts: 229
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    *bump*

    Anybody know anything about using JFR for testing?
     
    Sheriff
    Posts: 17734
    302
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Are you referring to Java Flight Recorder? https://docs.oracle.com/javacomponents/jmc-5-4/jfr-runtime-guide/about.htm#JFRUH170
     
    Junilu Lacar
    Sheriff
    Posts: 17734
    302
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Ted Gress wrote:I use a lot of static classes and threads and I think that's part of it but I'm not convinced that's the only problem lurking.


    The biggest, most obvious problem with that code is that it's a Big Ball of Mud.  There are almost always other problems lurking in BBoMs.
     
    Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic