help me with the error of Java related to UNIX


 
Thread Tools Search this Thread
Top Forums Programming help me with the error of Java related to UNIX
# 1  
Old 08-03-2007
help me with the error of Java related to UNIX

Can you help me with my code?
I wrote a Java program and ran it in gdb, the debugger said that :
Code:
(gdb) run handhelditems 1 1000
Starting program: /home/wqq/crawl/handhelditems/crawl_what_i_want handhelditems 1 1000
[Thread debugging using libthread_db enabled]
[New Thread -1208232256 (LWP 3796)]
[New Thread -1210332272 (LWP 3799)]
[New Thread -1220822128 (LWP 3800)]
[New Thread -1231311984 (LWP 3801)]
[New Thread -1243206768 (LWP 3802)]
[New Thread -1253696624 (LWP 3803)]
[New Thread -1264186480 (LWP 3804)]
[New Thread -1274676336 (LWP 3805)]
[New Thread -1285166192 (LWP 3806)]
[New Thread -1295656048 (LWP 3807)]
[New Thread -1306145904 (LWP 3808)]
[New Thread -1316635760 (LWP 3809)]

Program received signal SIGPWR, Power fail/restart.
[Switching to Thread -1316635760 (LWP 3809)]
0x00196402 in __kernel_vsyscall ()
(gdb) 

-------------------------------------------
the crawl_what_i_want.java is :
-------------------------------------------
public class crawl_what_i_want {
	public static void main(String[] args){
		if(args.length!=3){
			System.out.println("Usage: java crawl_html [site name] [start at] [end at]");
		}
		else
		{
			String v1 = args[0];
			int v2 = Integer.parseInt(args[1]);
			int v3 = Integer.parseInt(args[2]);
			
			thread thread0 = new thread(v1,v2,v3,0);
			thread thread1 = new thread(v1,v2,v3,1);
			thread thread2 = new thread(v1,v2,v3,2);
			thread thread3 = new thread(v1,v2,v3,3);
			thread thread4 = new thread(v1,v2,v3,4);
			thread thread5 = new thread(v1,v2,v3,5);
			thread thread6 = new thread(v1,v2,v3,6);
			thread thread7 = new thread(v1,v2,v3,7);
			thread thread8 = new thread(v1,v2,v3,8);
			thread thread9 = new thread(v1,v2,v3,9);

			thread0.start();
			thread1.start();
			thread2.start();
			thread3.start();
			thread4.start();
			thread5.start();
			thread6.start();
			thread7.start();
			thread8.start();
			thread9.start();

		}
	}
}
---------------------------------------------
the thread.java is :
---------------------------------------------
import java.io.*;
import java.sql.*;
import java.util.*;
import java.net.*;

public class thread extends Thread
{
	String site_n;
	int s_at;
	int e_at;
	int for_id;
	thread(String site_n,int s_at,int e_at,int for_id){
		this.site_n = site_n;
		this.s_at = s_at;
		this.e_at = e_at;
		this.for_id = for_id;
	}
	public synchronized void run() {
		String site = site_n;
		int fornum = for_id;
		int start = s_at;
		int end = e_at;
		//String site_name = "http://www."+site+".com";
		ArrayList url_list = new ArrayList();
		ArrayList url_id_list = new ArrayList();
		try{
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			String getconn = "jdbc:mysql://localhost/url_set_"+site+"?user=xxxx&password=xxxx";
			Connection conn = DriverManager.getConnection(getconn);
			PreparedStatement stmt = conn.prepareStatement("");
			ResultSet rs = null;
			stmt = conn.prepareStatement("select url,url_id from urls where url_id>=? and url_id<=?");
			stmt.setInt(1,start);
			stmt.setInt(2,end);
			rs = stmt.executeQuery();
			while(rs.next())
			{
				url_id_list.add(rs.getString(2));
				url_list.add(rs.getString(1));
			}
			if(rs!=null)
				rs.close();
			stmt.close();
			conn.close();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		try{
			InputStream in = null;
			InputStreamReader rd = null;
			BufferedReader br = null;
			for(int i=fornum; i<url_list.size(); i=i+10){
				
				String save_dir = "./" + String.valueOf(Integer.parseInt(url_id_list.get(i).toString())/10000) + "/" ;
				try{
					if(!(new File(save_dir).isDirectory()))
						new File(save_dir).mkdir();
				}
				catch(Exception exp){
					exp.printStackTrace();
				}
				String html = "";
				URL this_url = new URL(url_list.get(i).toString());
                in = this_url.openConnection().getInputStream();
                rd = new InputStreamReader(in);
                br=new BufferedReader(rd);
                String line = br.readLine();
                int imgmark = 0 ;
                while(line != null){
                    html += line + (char)13;
                    /////////////////
                    //  get image  //
                    /////////////////
                    if(line.indexOf("product image(s) bof")>0)
                    {
                    	imgmark = 1;
                    }
                    if(line.indexOf("product image(s) eof")>0)
                    {
                    	imgmark = 0;
                    }
                    if(imgmark == 1 && line.indexOf("img src")>=0)
                    {
                    	int bofimg = line.indexOf("https://www.unix.com/images/");
                    	int eofimg = line.indexOf("jpg\"")+3;
                    	if(eofimg>bofimg){
		                	String imgURL = "http://www."+site+".com/" + line.substring(bofimg,eofimg);
		                	String imgdir = save_dir + url_id_list.get(i).toString() + ".jpg";
		                	getpic gp = new getpic();
		                	gp.crawlpic(imgURL,imgdir);
                    	}
                    }
                    
                    line = br.readLine();
                }
                
	            br.close();
	            rd.close();
	            in.close();
                
				
				if(html==null)
					html = "";
				if(html.length()>0){
					String saveTo = save_dir+ url_id_list.get(i).toString() +".html";
					try {
						new outPut(html, saveTo);
					} catch (IOException e) {
						e.printStackTrace();
					}
					System.out.println((i+start) + ". Saved " + url_list.get(i) + " as " + (i+start) + ".html");
				}
				else
					System.out.println((i+start) + ". failed at " + url_list.get(i));
			}
			if(br!=null)
				br.close();
		}catch (Exception e){
			e.printStackTrace();
		}
	}	
}

------------------------------------------
the outPut.java is :
------------------------------------------
import java.io.*;

public class outPut {

        public outPut(String content, String outPutFile)throws IOException{
                FileWriter fl = null;
                BufferedWriter bw = null;
                try{
                        File f = new File(outPutFile);
                        if(!f.exists())
                                f.createNewFile();
                        fl = new FileWriter(outPutFile);
                        bw = new BufferedWriter(fl);
                        bw.write(content);
                }
                finally{
                        if(bw!=null)
                                bw.flush();
                        if(fl!=null)
                                fl.flush();
                        if(bw!=null)
                                bw.close();
                        if(fl!=null)
                                fl.close();
                }

        }

}

----------------------------
the getpic.java is
----------------------------
import java.io.*;
import java.net.*;
public class getpic {
        public synchronized void crawlpic(String url, String savedir)throws Exception {
            InputStream in = null;
            InputStream inBuffer = null;
            OutputStream out = null;            
            try{
                URL this_url = new URL(url);
                in = this_url.openConnection().getInputStream();
                    inBuffer = new BufferedInputStream(in);
                    out = new FileOutputStream(savedir);
                    while(true){
                    int bytedata = inBuffer.read();
                    if(bytedata == -1)
                    break;
                    out.write(bytedata);
                    }
            }
            finally{
                if(out != null)
                        out.close();
                if(inBuffer != null)
                        inBuffer.close();
                if(in != null)
                        in.close();
            }
    }


}

above are all my code .

Last edited by cf.george; 08-06-2007 at 04:33 AM.. Reason: code tags
# 2  
Old 08-03-2007
Note: I am not a java guy, so this is only from whatever I've searched on the net.

Are you using GNU Java Compiler?
This link will take you to the Wikipedia page of SIGPWR. There I followed another link to the Boehm garbage collector.

Unless your program is failing due to reception of SIGPWR, I think that this just has to do with GC and there shouldn't be any problems.

Of course, I could be very wrong here.
# 3  
Old 08-03-2007
That's very weird , it runs very well by jdb . I don't know where the problem is , but , anyway , it is running now Smilie
Thank you for your suggestion.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Unable to correct NMONVisualizer java error. Can someone help to decode this java error?

Hello AIX and Java gurus, I have a java error that I have no clue how to resolve. I am trying to run the popular NMONVisualizer utility against a NMON dataset and getting the error as shown below: /db2storage/NMON >java -jar NMONVisualizer_2015-02-02.jar com.ibm.nmon.ReportGenerator... (1 Reply)
Discussion started by: okonita
1 Replies

2. Shell Programming and Scripting

need downloading related help...but its not related to unix

Hi All, I am trying to dowmload the zip file "zkManageCustomers.zip " but i dont have access. Can anyone help me to download this file See the below link- http://www.ibm.com/developerworks/opensource/library/wa-aj-open/index.html?ca=drs- Please help me as early as... (1 Reply)
Discussion started by: aish11
1 Replies

3. UNIX for Advanced & Expert Users

Unix commands Related to

Hi all, Does unix has any commands for creating BLOB and CLOB objects. Please forward me any sites or samples (2 Replies)
Discussion started by: rajeshorpu
2 Replies

4. Fedora

How is OS X related to unix

Ok, I gotta ask this question, I have just begun fundamentals of UNIX in college and have learned or heard that Mac's OS-X is a linux based os! Does this mean that unix shell commands work in OS-X? I have no experience with os-x yet. I know it's a stupid question but I gotta know! (10 Replies)
Discussion started by: boarder428
10 Replies

5. Programming

Issue Related to Splash Screen in Java

Hi all, Actually I want to flash the image which I have in my system and when I am trying to do it,it is not showing it.simply creates the frame but not displaying the image.I am attaching the code-- Please take a look on it and please provide your valuable suggestions on it so that I... (2 Replies)
Discussion started by: smartgupta
2 Replies

6. Forum Support Area for Unregistered Users & Account Problems

How to post a new thread (Regarding Unix related doubts) in Unix Forums

How to post a new thread (Regarding Unix related doubts) in Unix Forums. I registered my id but I am unable to post my Questions to Forum. Thanks & Regards, indusri (1 Reply)
Discussion started by: indusri
1 Replies

7. Shell Programming and Scripting

Simple Shell Script Question.... [java related]

Hey guys! This is my first post, as im new here :S I have a simple problem for a big program. We have a .sh to install it, but when I run the .sh in terminal like i should, It says the class is not found. I believe it has to do with the syntax, as the person who made it is not a linux pro. I... (3 Replies)
Discussion started by: Drags111
3 Replies

8. UNIX for Dummies Questions & Answers

Receiving error on Unix server-- java.lang.UnsatisfiedLinkError: registerNatives

Hi all, This is my first shell script, so I'm hoping the problem is that I'm just missing something, and not something bigger. I have a Java application that I wrote in WSAD that reads data from an Excel file and inserts values into a DB2 database. I'm able to run it successfully in WSAD. I... (4 Replies)
Discussion started by: loveToBlade
4 Replies

9. UNIX for Dummies Questions & Answers

Question related to Emailing from UNIX

Hi All, I would like to write a script which sends an email to clients. mailx -s "TEST" $EMAIL_RECIPIENTS < FILE ...will send an email to EMAIL_RECIPIENTS with TEST as the subject and FILE as the body. Now I have a another CONTROL_FILE which is constant all the times (FILE in the above... (1 Reply)
Discussion started by: jingi1234
1 Replies

10. UNIX for Dummies Questions & Answers

Unix Related

well through my 6 months education i know some unix os but i can't find one for my p3 via board can any one tell me where to find such please replay as email or private msg and thanks (3 Replies)
Discussion started by: JaMaL
3 Replies
Login or Register to Ask a Question