0

I'm trying to design an android app but struggling with structure.

Basically from the UI action I need to run a thread to do some heavy maths work and this thread will run for a set amount of time set by variable from UI which isn't constant each time its run.

After this thread has completed and generated a result I then am thinking it will return to the ui thread and then I need to start another thread for another heavy maths work again for a set amount of time which is diff from the first thread and generate another number and then return to the UI thread.

so UI thread which has two variables Time A, and Time B button on UI thread "Start"

thread 1 starts does maths till Time A passes result of maths passed back to UI

UI then starts thread 2 but only when thread 1 is complete

Thread 2 started does maths till Time B passes result of maths passed back to UI

UI displays result of first thread and second thread

Hope this makes sense

  • 2
    Are you familiar with the `wait` and `notify` methods of the [`Object`](http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html) class? – ajb Apr 29 '14 at 23:36
  • I'll read up on them, I presume I'm not running both thread 1 and thread 2 at same time but putting a wait in thread 2 until it gets a notify from thread 1 as that seems wasteful on resources. Can I put a wait in the UI thread wont that make it hang? – Epiphanisation Apr 30 '14 at 00:13
  • `wait` could block the UI thread, so it may not be wise to put it there. Possible alternative: have the UI thread start thread 2 right away, but then thread 2 starts out by waiting on some synchronization object, possibly before it allocates any large objects. I'm just throwing some possibilities out there, I'm not sure which ones are appropriate for your app. – ajb Apr 30 '14 at 01:24

0 Answers0