2017년 8월 29일 화요일

jsoup url 3times

jsoup java 샘플 소스
 public static void main(String[] args) {  
     String[] urls = new String[]{"http://www.dmoz.org/", "http://www.dmoz.org/Computers/Computer_Science/","https://docs.oracle.com/en/"};  
     // Create and start workers  
       List workers = new ArrayList<>(urls.length);  
    for (String url : urls) {  
       Worker w = new Worker(url);   
   workers.add(w);   
   new Thread(w).start();  
   }  
     // Retrieve results    
       for (Worker w : workers) {  
       Elements results = w.waitForResults();  
       if (results != null)  
         System.out.println(w.getName()+": "+results.size());  
   else  
         System.err.println(w.getName()+" had some error!");    }  
   }  
 }  
 class Worker implements Runnable {  
   private String url;   
  private Elements results;  
   private String name;  
   private static int number = 0;  
   private final Object lock = new Object();  
   public Worker(String url)  
  {  
     this.url = url;  
     this.name = "Worker-" + (number++);  
  }  
   public String getName()  
  {  
     return name;  
  }  
   @Override  
   public void run() {  
     try {  
       Document doc = Jsoup.connect(this.url).get();  
       Elements links = doc.select("a");  
       // Update results  
       synchronized (lock) {  
         this.results = links;  
         lock.notifyAll();  
   }  
     } catch (IOException e) {  
       // You should implement a better error handling code..  
       System.err.println("Error while parsing: "+this.url);  
       e.printStackTrace();  
   }  
   }  
   public Elements waitForResults() {  
     synchronized (lock) {  
       try {  
         while (this.results == null) {  
           lock.wait();  
    }  
         return this.results;  
   } catch (InterruptedException e)  
   {  
         // Again better error handling  
         e.printStackTrace();  
   }  
       return null;  
   }  
   }  

text base network monitor tools


text base network monitor tools

nload
iftop
iptraf
nethogs
bmon
tcptrack
speedometer
pktstat
netwatch
trafshow

2017년 8월 28일 월요일

뒤로가기 두번 나가기

public boolean onKeyDown(int keyCode, KeyEvent event){
        switch(keyCode){
            case KeyEvent.KEYCODE_BACK:
                String alertTitle = "Auto Scheduler";
                String buttonMessage = "어플을 종료하시겠습니까?";
                String buttonYes = "Yes";
                String buttonNo = "No";
 
                new AlertDialog.Builder(majSelectActivity.this)
                        .setTitle(alertTitle)
                        .setMessage(buttonMessage)
                        .setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
 
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub
                                moveTaskToBack(true);
                                finish();
                            }
                        })
                        .setNegativeButton(buttonNo, null)
                        .show();
        }
        return true;
 
    }


출처: http://twinw.tistory.com/33 [흰고래의꿈]