# Is there a way to put the entire function signature with arguments into the thread call?

**URL:** <https://discourse.processing.org/t/is-there-a-way-to-put-the-entire-function-signature-with-arguments-into-the-thread-call/40880>\
**Category:** Beginners\
**Created:** [February 8, 2023, 11:25pm UTC](https://discourse.processing.org/t/is-there-a-way-to-put-the-entire-function-signature-with-arguments-into-the-thread-call/40880 "2023-02-08T23:25:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![advancecoder](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/advancecoder/32/6082_2.png) [@advancecoder](https://discourse.processing.org/u/advancecoder)\
**Post date:** [February 8, 2023, 11:25pm UTC](https://discourse.processing.org/t/is-there-a-way-to-put-the-entire-function-signature-with-arguments-into-the-thread-call/40880/1 "2023-02-08T23:25:24Z")

</div>

Hi,

Is there a way to put the entire function signature with arguments into the thread call? What would you add to the “requestData” call?

> **[thread() / Reference](https://processing.org/reference/thread_.html)**
>
> Processing sketches follow a specific sequence of steps: setup() first, followed by draw() over and over and over again in a loop. A thread is also a series of steps with a beginning, a …

```auto
String time = "";

void setup() {
  size(100, 100);
}

void draw() {
  background(0);
  // Every 30 frames request new data
  if (frameCount % 30 == 0) {
    thread("requestData");
  }
  text(time, 10, 50);
}

// This happens as a separate thread and can take as long as it wants
void requestData() {
  JSONObject json = loadJSONObject("http://time.jsontest.com/");
  time = json.getString("time");
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 9, 2023, 2:34am UTC](https://discourse.processing.org/t/is-there-a-way-to-put-the-entire-function-signature-with-arguments-into-the-thread-call/40880/2 "2023-02-09T02:34:58Z")

</div>

> [@advancecoder](#):
>
> Is there a way to put the entire function signature with arguments into the thread call?

Unfortunately no! Processing functions [**thread()**](https://processing.org/reference/thread_.html) & [**method()**](http://processing.github.io/processing-javadocs/core/processing/core/PApplet.html#method-java.lang.String-) can only invoke functions w/ signature `void ()` that belong to PApplet.

Unless you create your own Thread subclass:  
[https://docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Thread.html](https://docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Thread.html)

Just like we do w/ Processing callbacks **setup()**, **draw()**, **mousePressed()**, etc., we rely on “global” variables; both to “send” & “return” data.

BtW, your posted [**thread()**](https://processing.org/reference/thread_.html)'s example code keeps recreating a Thread @ 30 FPS.

Given we just need the same Thread code for the duration of the sketch, we can keep it alive via an infinite loop + **delay()**:

> **[delay() / Reference](https://processing.org/reference/delay_.html)**
>
> The delay() function causes the program to halt for a specified time. Delay times are specified in thousandths of a second. For example, running delay(3000) will stop the program for thr…

```auto
String time = "";

void setup() {
  size(300, 100);

  fill(#FFFF00);
  textSize(050);
  textAlign(CENTER, CENTER);

  thread("jsonDataLoop");
}

void draw() {
  background(#0000FF);
  text(time, width >> 1, height >> 1);
}

void jsonDataLoop() {
  for (;; delay(50))
    time = loadJSONObject("http://Time.JSONTest.com").getString("time");
}

```

Notice that on this modified version we only invoke **thread()** once within **setup()**.
