1
class MyTask extends AsyncTask<String, Void, String> {
    protected String doInBackground(String... params) {
        Thread a = new Thread(new Tread1()).start();
        Thread b = new Thread(new Tread2()).start();
    }
}

class Thread1 implements Runnable {
    public void run() {
    }
}

class Thread2 implements Runnable {
    public void run() {
    }
}

Is this possible instantiate 2 tread inside an asynctask in android? What are the pros and cons of this style?

ngrashia
  • 9,869
  • 5
  • 43
  • 58
Piolo Opaw
  • 1,471
  • 2
  • 15
  • 21
  • 1
    `doInBackground` is already running as a background thread, so why start another two threads from a background thread? A better approach would be to starts two AsyncTasks. – Martin Konecny Jun 02 '14 at 03:25
  • but is it posible to create Threads inside an Asynctask? – Piolo Opaw Jun 02 '14 at 03:53
  • I've never tried it, since it doesn't seem like a good idea. But why don't you try it? – Martin Konecny Jun 02 '14 at 03:54
  • i want to create something like syncronized method that tread1 and tread2 will not run until there a value of the String s = "name"; somthing like that, how to create somthing like that using syncronized method? using Thread only – Piolo Opaw Jun 02 '14 at 04:04
  • You can do that. You can start n no of Threads through async task, but that threads should be created in Main. I never tried with creating thread in AsyncTask. – Rohit Jun 02 '14 at 04:54

0 Answers0