The example sketch “Threaded PGraphics II” from 2nd link is for when we need to use an OpenGL PGraphics in another Thread.
If you don’t need an OpenGL PGraphics, go w/ the example sketch “Linked Balls” from the 1st link:
Or go w/ “Threaded PGraphics” from this link: