<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Java蜘蛛人 歡迎大家

    歡迎大家 來到我的blog , 如果我身邊的朋友 有什么不懂可以直接來問我 我會細心的幫助你的. 如果網絡上的朋友有什么不懂的 可以加我Java蜘蛛人 QQ48187537
    posts - 54, comments - 192, trackbacks - 0, articles - 1
    簡單的概括下多線程的用法
     

    多線程

     

    class NewThread implements Runnable

    {

           Thread t;

           NewThread()

           
    {

                  t
    =new Thread(this);

                  System.out.println (
    "NewTread 啟動了啊");

                  t.setPriority(
    3);

                  t.start();

           }


     
    public void run()

           
    {

                  
    try

                  
    {

                         
    for(int i=5;i>0;i--)

                                System.out.println (
    "NewThread:"+i);

                                Thread.sleep(
    500);

                  }


                  
    catch(Exception e)

                  
    {

                         e.printStackTrace();

                  }


           }


    }


    class Test2 extends Thread

    {

           Thread t;

           Test2()

           
    {

                  t
    =new Thread(this);

                  System.out.println (
    "Test啟動了");

                  t.setPriority(
    4);

                  t.start(); 

        }
         

                      
    public void run()

                         
    {

                         
    try

                         
    {

                                
    for(int i=5;i>0;i--)

                                       System.out.println (
    "Test2::"+i);

                           

                         }


                         
    catch(Exception e)

                         
    {

                                e.printStackTrace();

                         }


                      }


    }


    public class ThreadDemo implements Runnable

    {

           Thread a;

           ThreadDemo()

           
    {

                  a
    =new Thread(this);

                  System.out.println (
    "執行到main外");

                  a.setPriority(
    5);

                  a.start();

           }


           
    static int aa=0;

                  
    public void run()

                  
    {

                  
    try

                  
    {

                         System.out.println (
    "main::開始了啊");

                         
    for(int i=5;i>0;i--)

                                System.out.println (
    "main:"+i);      

                                
    if(aa++==2)

                                       a.yield();a.sleep(
    1000);

                  }


                  
    catch(Exception e)

                  
    {

                         e.printStackTrace();

                  }


                  }


           
    public static void main (String[] args) 

           
    {

                  
    new NewThread();

                  
    new Test2();

                  
    new ThreadDemo();

        }


    }



     

    對象流的存儲。。。

     
    import java.util.*;
    import java.io.*;
    public class ObjectFileTest
    {
        
    public static void main (String[] args) 
        
    {
            Manager boss
    =new Manager("xiaoqiao",80000,2008,05,06);
            boss.setBoss(
    5000);
            System.out.println (boss);
            
            Employee [] staff
    =new Employee[3];
            staff[
    0]=boss;
            staff[
    1]=new Employee("xiongdi",8,2007,05,06);
            staff[
    2]=new Employee("asd",1000,2004,05,06);
            
    try
            
    {
                ObjectOutputStream out
    =new ObjectOutputStream(new FileOutputStream("zcq.doc"));
                out.writeObject(staff);
                out.close();
                
                ObjectInputStream in
    =new ObjectInputStream(new FileInputStream("zcq.doc"));
                Employee[] newStaff
    =(Employee[])in.readObject();
                in.close();
                
    for(Employee e:newStaff)
                    System.out.println (e);
            }

            
    catch(Exception e)
            
    {
                e.printStackTrace();
            }

        }

    }

    class Employee implements Serializable
    {
        
    private String name;
        
    private double salary;
        
    private Date hireDay;
        
    public Employee()
        
    {
        }

        
    public Employee(String n,double s,int year,int month,int day)
        
    {
            name
    =n;
            salary
    =s;
            GregorianCalendar calendar
    =new GregorianCalendar(year,month-1,day);
            hireDay
    =calendar.getTime();
        }

        
    public String getName()
        
    {
            
    return name;
        }

        
    public double  getSalary()
        
    {
            
    return  salary;
        }

        
    public Date getHireDay()
        
    {
            
    return hireDay;
        }

        
    public String toString()
        
    {
            
    return "name:"+name
                
    +"     salary:"+salary
                    
    +"    時間是:"+hireDay;
        }

        
    }

    class Manager extends Employee
    {
        
    private double bouss;
        
    public Manager(String n,double s,int year,int month,int day)
        
    {
            
    super(n,s,year,month,day);
        }

        
    public double getSalary()
        
    {
            
    double aa=super.getSalary();
            
    return aa+bouss;
        }

        
    public void setBoss(double b)
        
    {
            bouss
    =b;
        }

        
    public String toString()
        
    {
            
    return super.toString()+"boss:"+bouss;
        }

        
    }




     

    保存對象引用問題

    一個經理共享一個秘書和一個雇員

    import java.util.*;
    import java.io.*;
    public class ObjectRefTest
    {
        
    public static void main (String[] args) 
        
    {
            Employee harry
    =new Employee("harry asd",5000,1989,10,1);
            Manager boss
    =new Manager("Carl Cracker",8000,1987,12,12);
            boss.setSecretary(harry);
            
            Employee[] staff
    =new Employee[3];
            staff[
    0]=boss;
            staff[
    1]=harry;
            staff[
    2]=new Employee("zcq123",8000,1990,3,15);
            
            
    try
            
    {
                ObjectOutputStream out
    =new ObjectOutputStream(new FileOutputStream("zcq.doc"));
                out.writeObject(staff);
                out.close();
                
                ObjectInputStream in
    =new ObjectInputStream(new FileInputStream("zcq.doc"));
                Employee[] newStaff
    =(Employee[])in.readObject();
                in.close();
                
                newStaff[
    1].ticheng(10);
                
                
    for(Employee e:newStaff)
                
    {
                    System.out.println (e);
                }

            }

            
    catch(Exception e)
            
    {
                e.printStackTrace();
            }

        }

    }

    class Employee implements Serializable
    {
        
    private String name;
        
    private double salary;
        
    private Date hireDay;
        
    public Employee(){}
        
    public Employee(String n,double s,int year,int month,int day)
        
    {
            name
    =n;
            salary
    =s;
            GregorianCalendar calendar
    = new GregorianCalendar(year,month-1,day);
            hireDay
    =calendar.getTime();
        }

        
    public String getName()
        
    {
            
    return name;
        }

        
    public double getSalary()
        
    {
            
    return salary;
        }

        
    public Date getHireDay()
        
    {
            
    return hireDay;
        }

        
    public void ticheng(double aa)
        
    {
            
    double bb=salary*aa/100;
            salary
    =salary+bb;
        }

        
    public String toString()
        
    {
            
    return getClass().getName()+"   name:"
                
    +name+"   salary:"+salary
                    
    +"   hireday"+hireDay;
        }

    }

     
    class Manager extends Employee
    {
        
    public Manager(String n,double s ,int year,int month,int day)
        
    {
            
    super(n,s,year,month,day);
            secretary
    =null;
        }

        
    public void setSecretary(Employee s)
        
    {
            secretary
    =s;
        }

        
    public String toString()
        
    {
            
    return super.toString()+"  secretary"+secretary;
        }

        
    public Employee secretary;
    }



     

    適合初學者看的克隆 一看就懂

    public class Test
    {
        
    public static void main (String[] args) 
        
    {
            Test1 aa
    =new Test1();
            
    try
            
    {
            Test1 bb
    =aa.clone();
            }

            
    catch(CloneNotSupportedException e)
            
    {
                e.printStackTrace();
            }

        }

    }

    class Test1 implements Cloneable
    {
        
    public Test1 clone() throws CloneNotSupportedException //拋出這個異常 .. 
        {
            Test1 aa
    =(Test1)super.clone();
            
    return aa;
        }

    }


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 久久精品国产亚洲av高清漫画| 亚洲人成综合在线播放| 久久免费福利视频| 亚洲国产成人精品电影| 国产又粗又长又硬免费视频| 中国一级毛片免费看视频| 亚洲精品成人久久| 国产真实伦在线视频免费观看| 久青草视频在线观看免费| 91亚洲精品自在在线观看| 五月婷婷亚洲综合| 3d动漫精品啪啪一区二区免费| 亚洲GV天堂无码男同在线观看 | 亚洲精品无码mv在线观看网站| 1000部羞羞禁止免费观看视频| 校园亚洲春色另类小说合集| 婷婷亚洲综合五月天小说| 国产青草视频免费观看97| 99在线观看精品免费99| 视频一区在线免费观看| 亚洲人成人77777网站不卡| 亚洲一区二区三区偷拍女厕 | 黄色免费在线网站| 美女羞羞免费视频网站| 亚洲日韩国产精品无码av| 亚洲无码高清在线观看| 国内自产拍自a免费毛片| 久久九九AV免费精品| 特a级免费高清黄色片| 色老板亚洲视频免在线观| 亚洲av最新在线网址| 亚洲国产黄在线观看| 午夜爱爱免费视频| 精品免费人成视频app| 久久精品国产免费一区| 性生大片视频免费观看一级 | 国产乱子精品免费视观看片| 你懂的网址免费国产| 色多多免费视频观看区一区| 亚洲中文字幕精品久久| 亚洲精品日韩专区silk|