0

Using inputstream.readUTF() and a DataInputStream we are required to use a single thread to continuously check for null and to iterate over our input stream. From what I have found online, JavaFX does not provide any way of implementing concurrency or multithreading while also allowing dynamic updating of nodes. Is there something I am over looking? Because this dynamic updating of nodes from a stream has been impossible. The task I am trying to perform is to take an input stream and populate a Pane with the text received.

I have tried Platform.runlater, I have tried Task, I have also looked into executor but don't believe it to be what I am looking for.

ccbrantley
  • 52
  • 7
  • 4
    [Concurrency in JavaFX](https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/concurrency.htm) – Abra Oct 23 '19 at 03:41
  • 4
    [JavaFX periodic background task](https://stackoverflow.com/questions/9966136/javafx-periodic-background-task) – Abra Oct 23 '19 at 03:47
  • 3
    I’m curious where you found this online. Do you have a reference? – jewelsea Oct 23 '19 at 03:59
  • Abra, the timeline example works. Thank you for sharing this! – ccbrantley Oct 23 '19 at 05:20
  • 3
    Keep in mind using the animation API means you're using the _JavaFX Application Thread_. If your periodic task is blocking or otherwise long-running then you really should be using a background thread. You can post updates to the UI with `Platform.runLater`. The `Worker` interface, which `Task` implements, is designed to ease this process. You mention you tried these options but for whatever reason they didn't work for you. In what way did they fail? Can you provide a [mre]? Note that while multi-threading in JavaFX requires certain rules to be followed it certainly is possible to use. – Slaw Oct 23 '19 at 06:20
  • 1
    If `Platform.runLater` does not work well, the other solution is to post something to a thread-safe data structure, like `ArrayBlockingQueue`, and check there periodically with a `timeline` for new data. Whatever you do, don't mess with `Observables` from multiple threads. – SephB Oct 23 '19 at 21:28

0 Answers0