# How can I use Thread() with functions that has inputs

**URL:** https://discourse.processing.org/t/how-can-i-use-thread-with-functions-that-has-inputs/12964
**Category:** Coding Questions
**Created:** [July 25, 2019, 8:08am UTC](https://discourse.processing.org/t/how-can-i-use-thread-with-functions-that-has-inputs/12964 "2019-07-25T08:08:28Z")
**Posts on this page:** 1
**Showing post:** 2

<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: [July 25, 2019, 8:35am UTC](https://discourse.processing.org/t/how-can-i-use-thread-with-functions-that-has-inputs/12964/2 "2019-07-25T08:35:37Z")

</div>

> [@Majorminus](#):
>
> How can I use **thread()** function correctly in this kind of situation?

You can’t, b/c its signature is parameterless & `void`. ⛔

Instead, you can create a `class` which `extends` Thread: 🧵  
[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Thread.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Thread.html)

```auto
/**
 * Threaded Method (v1.0.1)
 * GoToLoop (2019/Jan/)
 *
 * https://Discourse.Processing.org/t/
 * how-can-i-use-thread-with-functions-that-has-inputs/12964/2
 */

void setup() {
  noLoop();
}

void draw() {
  background((color) random(#000000));
}

void mousePressed() {
  new ThreadedMethodWithIntParameter((int) random(100));
}

class ThreadedMethodWithIntParameter extends Thread {
  final int input;

  ThreadedMethodWithIntParameter(final int inp) {
    input = inp;
    start();
  }

  @Override void run() {
    println(input);
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/how-can-i-use-thread-with-functions-that-has-inputs/12964)._
