Multi Threading is not working in that why...?

Multi Threading is not working in that why...?

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;

public class FileSpliting {

static byte[] dataBytes1 = new byte[100000000]; static byte[] dataBytes2 = new byte[100000000];

public static void main(String[] args) throws IOException { String filename = "users14.dbf"; System.out.println("File Name---"+filename); File file = new File(filename); System.out.println("size---"+file.length());

long sz=file.length();
int totalChunk=(int) (sz/100000000)+1;
int len = 0;
try {
    InputStream fp = new FileInputStream(file);
    int k=1;
    int i=0;
    int nextBuffer=1;

    while (totalChunk>0) {
        if (nextBuffer == 1)
        {
            len = fp.read(dataBytes1);  //read(dataBytes,(int) ps,1000);
            nextBuffer = 2;
        }
        else
        {
            len = fp.read(dataBytes2);  //read(dataBytes,(int) ps,1000);
            nextBuffer = 1;
        }
        i = i + len;
        System.out.println("Remaining-------------------------"+(sz-i));
        while (Thread.activeCount() == 5)
        {
            Thread.sleep(1);
        }

        if (nextBuffer == 2)
            new NewThread(filename,k,1,len);
        else
            new NewThread(filename,k,2,len);

        k++;
        totalChunk--;
    }
    file=null;
    while (Thread.activeCount() == 2)
    {
        Thread.sleep(1);
    }
    Date date= new Date();
    System.out.println("end of file---"+date);
}catch (Exception e) {
    e.printStackTrace();
}

} } class NewThread implements Runnable { Thread t; private String filename=null; private int j; File file=null; long len; private int no; //byte[] dataBytes1 = new byte[10000000]; FileSpliting fs=new FileSpliting();

NewThread(String filname,int j, int no,long len) { this.filename=filname; this.j=j; //this.dataBytes1=dataBytes1; this.len=len; this.no=no; t = new Thread(this, "file Thread"); // System.out.println("Child thread: " + t); t.start(); // Start the thread } @SuppressWarnings("static-access") public void run() {

File file1 = new File("ddd/"+j+"_"+filename);
try {
    System.out.println("success---"+file1.createNewFile());
    FileOutputStream myStream = new FileOutputStream(file1);
    if(no==1)
        myStream.write(fs.dataBytes1,0,(int)len);
    else
        myStream.write(fs.dataBytes2,0,(int)len);
    myStream.close();

} catch (Exception e) {
    e.printStackTrace();
}

} }

View Answers









Related Tutorials/Questions & Answers:
Multi Threading is not working in that why...?
Java multi-threading
Advertisements
Multi Threading
what is multi-threading .?
Java multi-threading
Java multi-threading
Multi-Threading - Java Beginners
multi threading - Java Interview Questions
multi threading code - Java Interview Questions
Threading
Threading Program
threading
Java RMI and Threading
ModuleNotFoundError: No module named 'extended_threading'
ModuleNotFoundError: No module named 'extended_threading'
ModuleNotFoundError: No module named 'micropython-threading'
ModuleNotFoundError: No module named 'micropython-threading'
ModuleNotFoundError: No module named 'pycopy-threading'
ModuleNotFoundError: No module named 'threading-futures'
ModuleNotFoundError: No module named 'threading-sched'
ModuleNotFoundError: No module named 'threading_tools'
ModuleNotFoundError: No module named 'click-threading'
ModuleNotFoundError: No module named 'continuous-threading'
ModuleNotFoundError: No module named 'extended_threading'
UITapgesturerecognizer not working
htpasswd working
ModuleNotFoundError: No module named 'pycopy-dummy_threading'
ModuleNotFoundError: No module named 'micropython-dummy_threading'
ModuleNotFoundError: No module named 'opencensus-ext-threading'
hibernate.archive.autodetection not working
Datagrid not working
multi language
multi thread
Why this is not working...?
Multi window
multi dimension
Update not working in hibernate.
Comparing arrays not working correctly?
how to call a frame having threading concept
Nitobi Grid is not working in IE10/IE11
Threading in Java
Threading In Java Example
Focus method not working in firefox
ModuleNotFoundError: No module named 'multi'
ModuleNotFoundError: No module named 'working'
ModuleNotFoundError: No module named 'working'
ModuleNotFoundError: No module named 'working'
calender working in struts - Struts
html dropdown not working firefox
about threading in java - Java Server Faces Questions

Ads