Below is my sample implementation code, where code running without proper threading takes less time than code running with proper threading implementation, Kindly advice what mistake I am making or issues in my code
@Override
public Integer timeTakenWithoutThreading() {
System.out.println("StartTime" + new Date());
Date startDate = new Date();
int value = 1000000;
int value2 = 2000000;
for (int i = 0; i <= value; i++) {
System.out.println("Value 1" + i);
}
for (int i = 0; i <= value2; i++) {
System.out.println("Value 2" + i);
}
System.out.println("StartTime" + startDate);
System.out.println("endTime" + new Date());
return null;
}
@Override
public String timeTakenWithThreading() {
Date start = new Date();
Date firstThread = new Date();
threadPoolExecutorService.execute(new Runnable() {
final int value = 1000000;
@Override
public void run() {
for (int i = 0; i <= value; i++) {
System.out.println("Thread 1 Value" + i);
}
}
});
threadPoolExecutorService.execute(new Runnable() {
final int value2 = 2000000;
@Override
public void run() {
for (int i = 0; i <= value2; i++) {
System.out.println("Thread 2 Value" + i);
}
System.out.println("Start Date" + start);
System.out.println("End Date" + new Date());
}
});
return "You Will Get Response So Soon But Thread Will Execute At the Background";
}
}```