1 java
我有一个java程序来读取输入文件(input.txt)并打印该文件的内容(之后我需要做更多的工作,即ssh到机器并检查状态,发送电子邮件等...).由于input.txt文件包含更多行,因此需要大约3小时才能完成程序.
所以喜欢在java中使用spawn概念(比如线程)或其他一些技术来在读取输入文件的同时溢出进程并在同一时间完成其他工作(ssh,checkstatus,send mail),这样程序几乎不需要十分钟完成该计划.
我是Java的新手.你能指导我如何把这个逻辑.我已经粘贴了我现在的代码.
input.txt文件的示例:
#Run Code Online (Sandbox Code Playgroud) #ABCbigboy 72.24.1 72.24.157.57
#
bejack 2.24.157.97 1.24.157.69 boni 2.24.147.96 9.24.159.86讽刺7.24.145.93 8.24.209.55Run Code Online (Sandbox Code Playgroud) #xyzalches 2.24.140.199 1.24.140.46
Java程序:
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.util.Calendar;
import java.net.*;
import java.net.UnknownHostException;
public class panic_email{
public static void main(String[] args) throws IOException{
try{
System.out.println ("Starting of program...");
FileInputStream fstream = new FileInputStream("input.txt");
DataInputStream input = new DataInputStream(fstream);
BufferedReader bfr = new BufferedReader(new InputStreamReader(input));
String Name = "";
String IP = "";
CSLOOP: while ((FileLine = bfr.readLine()) != null) {
FileLine = FileLine.trim();
if ( FileLine.startsWith("XYZ") ){
System.out.println ("End of program");
break;
}
if ( !FileLine.startsWith("#") && !FileLine.startsWith(" ") ){
String splitLine[] = null;
splitLine = FileLine.split("\\s+");
if( splitLine.length >= 3){
Name = splitLine[0];
Ip = splitLine[2];
System.out.println("Name:" + Name + "IP" + Ip);
//Here after this I am doing some kind of extra work like ssh,checkstate,send email. So while coming to this point I need to spawn the process i think.
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
你能指导我怎么做吗?
谢谢,瑞克斯
| 归档时间: |
|
| 查看次数: |
655 次 |
| 最近记录: |