I think what happens is that the thread eachother overides(cross each other) and thats why he give me the fault but i don't know how to solve the problem.
Here is my code
So when i click the button threadUpload will be called:
- Code: Select all
else if (evt.getSource() == bUpload)
{
try{
int maxRows;
int[] selRows;
selRows = table.getSelectedRows();
maxRows = table.getSelectedRowCount();
System.out.println("max"+maxRows);
if (selRows.length > 0) {
for (int a = 0; a < maxRows; a++){
for (int i= 0; i < 3 ; i++) {
if (i==1){
TableModel tm = table.getModel();
value = tm.getValueAt(selRows[a],i);
System.out.println("value:" + value);
threadUpload();
//wait(50000000);
}
}
}
}
} catch (Exception e){}
}
Then this is the tread thats starts the uploading
- Code: Select all
public void threadUpload() {
t = new Thread(new Runnable() {
public void run() {
//Get the path + name of the selected File
String allText = path+value;
System.out.println("filename:" + allText);
doUpload(allText);
}
});
try{
t.start();
} catch (Exception e){}
}
Then is this the code for uploaden the file:
- Code: Select all
public void doUpload(String filename) {
if (wrapper.isConnected()){
try{
wrapper.changeWorkingDirectory(Root);
wrapper.binary();
lUpload.setText("Uploading file : " + value);
lUpload.setVisible(true);
aProgressBar.setVisible(true);
aProgressBar.setStringPainted(true);
byte[] buffer = new byte[1024];
try {
String remoteFile = (String) value;
System.out.println("remotefile:"+remoteFile);
File f = new File(filename);
int size = (int) f.length();
FileInputStream in = new FileInputStream(filename);
OutputStream out = wrapper.storeFileStream(remoteFile);
int counter = 0;
double bytesUploaded = 0;
int percVal = 0;
System.out.println("Root: " + Root);
while ((counter = in.read(buffer)) >= 0 ) {
bytesUploaded += counter;
out.write(buffer,0,counter);
percVal = (int) ((bytesUploaded / size) * 100);
aProgressBar.setValue(percVal);
aProgressBar.setString("" + percVal + "%");
if (percVal == 100){
refreshUpload();
JOptionPane.showMessageDialog(this,"Uploaden geslaagd","Gelukt",JOptionPane.INFORMATION_MESSAGE);
lUpload.setVisible(false);
aProgressBar.setVisible(false);
}
}
out.close();
in.close();
} catch (Exception ex) {
System.out.println(ex);
JOptionPane.showMessageDialog(this,"Error: " + ex.toString(),"ERROR",JOptionPane.ERROR_MESSAGE);
aProgressBar.setVisible(false);
}
} catch (Exception ex) {
System.out.println(ex);
JOptionPane.showMessageDialog(this,"Connectie Error: " + ex.toString(),"ERROR",JOptionPane.ERROR_MESSAGE);
}
} else {
System.out.println("Geen connectie tijdens het uploaden...");
JOptionPane.showMessageDialog(this,"Geen connectie tijdens het uploaden","ERROR",JOptionPane.ERROR_MESSAGE);
connect();
return;
}
postUpload();
}
So my opinion is that the treads are being covered by the other when i upload more than 1 file.
I hope somebody can help me.
Satanduvel


