ورود

View Full Version : سوال: دانلود از اینترنت



mman7798@gmail.com
پنج شنبه 17 تیر 1400, 07:55 صبح
سلام
من داخل برنامه لازم دارم که هشتصد فایل چند بایتی ک خیلی کوچیکن را پشت سر هم از یک سایت دانلود کنم اما با این که حجم کل این فایلا یک مگ هم نمیشه و سرعت سایت بالاست و این کار را توی هشت نخ همزمان انجام میدم بازم خیلی طول میکشه حدودا یکی دو دقیقه توی یک نخ ک خیلی بیشتر بنظرتون اشکال کار کجاست مال اینه که هربار کانکشن باز و بسته میشه؟ بلد نیستم لطفا راهنمای کنید خیلی ضروری هستش
class RunAndRun implements Runnable {
private final int start, end;
public RunAndRun(int start, int end) {
this.start = start;
this.end = end;
Thread thread = new Thread(this);
thread.start();
}

public void run() {
for (int i = start; i < end; i++) {
SimpleModel simple = activity.simples.get(i);
CostModel model = new CostModel(simple);
costModels.add(model);
fillData(model);
progress++;
}
}

public void fillData(CostModel model) {
String data = "";
try {
URL url = new URL("http://............" + model.id + "&c=100");
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
byte[] bytes = new byte[500];
stream.read(bytes);
data = new String(bytes);
} catch (Exception e) {
e.printStackTrace();
}
کد خیلی سادس لینک اصلی ثابت‌هست و ادامه لینک از فیلد های ابجکت های جاوا برداشته میشه ادرس سایتو ب علتی پاک کردم

ehsan_feri
جمعه 22 مرداد 1400, 20:25 عصر
کدت رو بذار.

mman7798@gmail.com
جمعه 22 مرداد 1400, 23:19 عصر
class RunAndRun implements Runnable {
private final int start, end;
public RunAndRun(int start, int end) {
this.start = start;
this.end = end;
Thread thread = new Thread(this);
thread.start();
}


public void run() {
for (int i = start; i < end; i++) {
SimpleModel simple = activity.simples.get(i);
CostModel model = new CostModel(simple);
costModels.add(model);
fillData(model);
progress++;
}
}


public void fillData(CostModel model) {
String data = "";
try {
URL url = new URL("http://............" + model.id + "&c=100");
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
byte[] bytes = new byte[500];
stream.read(bytes);
data = new String(bytes);
} catch (Exception e) {
e.printStackTrace();
}