thread vs papplet.runsketch

Hi all, sorry if the question sounds silly, but I noticed that if I put someting in the PApplet.runsketch() extended void draw(), it works as a parallel thread. Does the second frame means having a multithreading applet? Thank you


  • What exactly are you talking about? Please give some code.

  • Yes, it creates another canvas w/ its own "Animation" Thread. :-B

  • I'm talking about the runSketch method that allow to have multiple windows.

    I'm not very expert in multi thread on processing, just recently i learned how to exthend the Thread class to pass arguments to it, before i was using only global variable.

    I'm wondering for example, in case let's say i want to create an app with a control panel and a preview panel that i can open and close, or having a separate thread for a long time database analysis that i don't want to stop the main program, if is better to use a separate thread and preview stuffs about it in another window or , instead, put the whole code of this parallel task in the second window draw() method.

  • edited February 2017

    Each PApplet ignited by runSketch() behaves almost as if it was a separate sketch. >-)

    With its own settings(), setup(), draw(), etc.
    With their own "Animation" Thread and input enqueueing events.

  • But still it can see global variables, right? Is it possible to stop it as well or i just can stop the loop and make it invisible?

  • edited February 2017

    But still it can see global variables, right?

    In order to prohibit your other PApplet subclasses to access the global instance fields from the top PApplet sketch, just declare them w/ static: static class MyOtherSketch extends PApplet {}

  • ... or i just can stop the loop and make it invisible?

    As long as a PApplet instance got access to the reference of another PApplet, the former can access members of the latter. :-bd

  • oh actually it's ok for me that they still can access global variables, i was just wondering if the idea to running threads as separate frames was better in some cases compared to others. thank you anyway :-)

Sign In or Register to comment.