I am having a file sub.srt and am reading that using multiple instances simultaneously. It works fine. Is this possible to work same in web application with Servlets and JSP?
This is the main file
public class SingleTest
{
public static void main(String args[]) throws Exception
{
String s[]= new String[10];
for(int i = 1;i<=10;i++)
{
SingleFileThread sft1 = new SingleFileThread(i);
sft1.start();
}
}
}
This is the Thread to create multiple instances to read a single file
public class SingleFileThread extends Thread
{
public int t =0;
public SingleFileThread(int i)
{
t = i;
}
public void run()
{
try{
File f = new File("E:\\Leo-Softwares\\workspace\\SingleFileThread \\src\\test\\sub.srt");
System.out.println("f.setReadOnly() :"+f.setReadOnly());
FileInputStream fstream = new FileInputStream(f);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
System.out.println ("Thread :"+t+"_____"+strLine);
Thread.sleep(2000);
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}
I didn’t get you?? Y u need to implement threads in jsp..What you exactly want to do..Because the tomcat container itself maintains the threads for your concern jsp.. What u want is may be about the session tracking i guess..Sorry but didn,t get your question properly…???