Doubt about multithreading

Hello, everybody!

I'm writing a little desktop application to make backups. The application

consists of a list of backup items, each item with source and destination, which

the user can configure. I want to make the backups sequentially, so when one

finishes, another one starts. I also want to make the backups in a separate

thread, using the SwingWorker class. But I was thinking with myself: If I am

going to use a separate thread to make the backup, why not make all the backup

items at the same time, scheduling a separate thread for each one? Wouldn't it

be faster? That's my doubt, as I know that when multiple threads are running in

the same application they are not really running at the same time, but using

time-slice controlled by the processor. So, how would Java react in a machine

with:

- one processor

- more than one processor (would Java divide the work between processors,

making the backup run faster?)

- a processor with the dual core technology (would it be faster here too?)

What I really need to know is that if I really gain something in time if I

schedule a thread for each backup item for the backups to execute at the same

time of if I would better stick with one backup item at a time.

Thank you.

Marcos

[1363 byte] By [Marcos_AntonioPSa] at [2007-11-26 21:17:07]
# 1

> What I really need to know is that if I really gain

> something in time if I

> schedule a thread for each backup item for the

> backups to execute at the same

> time of if I would better stick with one backup item

> at a time.

It depends on how many disks you have. Many "concurrent" read/writes on one disk will kill your performance.

Kaj

kajbja at 2007-7-10 2:55:52 > top of Java-index,Java Essentials,Java Programming...
# 2

> - one processor

> - more than one processor (would Java divide the work

> between processors, making the backup run faster?)

I think that's the OS's task, but yes, that would happen.

> a processor with the dual core technology (would it be faster here too?)

Yes.

In both cases: unless you're using shared devices like the same hard disk. Those don't work in parallel.

CeciNEstPasUnProgrammeura at 2007-7-10 2:55:52 > top of Java-index,Java Essentials,Java Programming...
# 3
> It depends on how many disks you have. Many> "concurrent" read/writes on one disk will kill your> performance.> > KajIn this case I'm talking about only one diskMarcos
Marcos_AntonioPSa at 2007-7-10 2:55:52 > top of Java-index,Java Essentials,Java Programming...
# 4

> > - one processor

> > - more than one processor (would Java divide the

> work

> > between processors, making the backup run

> faster?)

>

> I think that's the OS's task, but yes, that would

> happen.

Yes, this is a OS's task, thank you for the correction

Marcos

Marcos_AntonioPSa at 2007-7-10 2:55:52 > top of Java-index,Java Essentials,Java Programming...
# 5
> In both cases: unless you're using shared devices> like the same hard disk. Those don't work in parallel.So, are you saying that if I'm writing to the same disk I will not gain performance, so I would better stick with one thread at a time?Marcos
Marcos_AntonioPSa at 2007-7-10 2:55:52 > top of Java-index,Java Essentials,Java Programming...
# 6

> So, are you saying that if I'm writing to the same

> disk I will not gain performance, so I would better

> stick with one thread at a time?

You might actually lose performance, because of increased head repositioning: instead of writing continuously at one place, you'd write here, then you'd write there, then here again, then there again... you might also "outsmart" the disk caches that way.

Unless the writing process blocks somehow, there's no time you could save.

CeciNEstPasUnProgrammeura at 2007-7-10 2:55:52 > top of Java-index,Java Essentials,Java Programming...
# 7

> You might actually lose performance, because of

> increased head repositioning: instead of writing

> continuously at one place, you'd write here, then

> you'd write there, then here again, then there

> again... you might also "outsmart" the disk caches

> that way.

>

> Unless the writing process blocks somehow, there's no

> time you could save.

Yes, that's make a lot of sense. Thank you for the answer.

Marcos

Marcos_AntonioPSa at 2007-7-10 2:55:52 > top of Java-index,Java Essentials,Java Programming...