0

I'm learning about threads in java and I was trying to run QuickSort using two threads on one array, but didn't work as expected . The idea is to run one thread on the first part after the array's partition, and the second thread would run on the other part. I assumed using two threads running in parallel would improve the performance, but it didn't. After many tests, using the two threads was relatively worse than the regular original quicksort sorting.

I don't know what seems to be the problem.

Shifar
  • 1
  • 1
  • 2
  • see [Does multi-threading improve performance? How?](https://stackoverflow.com/questions/15292626/does-multi-threading-improve-performance-how). How many cores do you have ? And is the question correct ? It seems to work only not so fast in this case – pirho Oct 13 '17 at 19:41
  • I'm wondering how you benchmarked it? With 50 elements?! Did you read about how to do a proper micro-benchmark in Java? Have you heard about the Fork-Join framework of Java? – UninformedUser Oct 13 '17 at 19:42
  • @pirho I've a Core i3 processor (dual core). – Shifar Oct 13 '17 at 19:47
  • @AKSW The QuickSort works as same as the one in CLRS, where the pivot is the last element. I've read about Fork-Join framework, but is it the only way to use multiple threads in java ? – Shifar Oct 13 '17 at 19:51

1 Answers1

1

If I see correctly, you are using Thread.run() instead of Thread.start() to execute a thread (i.e. you should use tUpper.start() and tLower.start() in your code). Only the second method creates a new thread. First one does not - the method is executed in the calling thread.

See also this question.

lukeg
  • 4,189
  • 3
  • 19
  • 40