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

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

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

    Java蜘蛛人 歡迎大家

    歡迎大家 來(lái)到我的blog , 如果我身邊的朋友 有什么不懂可以直接來(lái)問(wèn)我 我會(huì)細(xì)心的幫助你的. 如果網(wǎng)絡(luò)上的朋友有什么不懂的 可以加我Java蜘蛛人 QQ48187537
    posts - 54, comments - 192, trackbacks - 0, articles - 1
    簡(jiǎn)單的概括下多線程的用法
     

    多線程

     

    class NewThread implements Runnable

    {

           Thread t;

           NewThread()

           
    {

                  t
    =new Thread(this);

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

                  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啟動(dòng)了");

                  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 (
    "執(zhí)行到main外");

                  a.setPriority(
    5);

                  a.start();

           }


           
    static int aa=0;

                  
    public void run()

                  
    {

                  
    try

                  
    {

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

                         
    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();

        }


    }



     

    對(duì)象流的存儲(chǔ)。。。

     
    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
                    
    +"    時(shí)間是:"+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;
        }

        
    }




     

    保存對(duì)象引用問(wèn)題

    一個(gè)經(jīng)理共享一個(gè)秘書和一個(gè)雇員

    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;
    }



     

    適合初學(xué)者看的克隆 一看就懂

    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 //拋出這個(gè)異常 .. 
        {
            Test1 aa
    =(Test1)super.clone();
            
    return aa;
        }

    }


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产乱码免费卡1卡二卡3卡| 免费无码成人AV在线播放不卡| 亚洲人成人网站18禁| WWW国产亚洲精品久久麻豆| 国产99久久亚洲综合精品| 波霸在线精品视频免费观看| 青青青国产手机频在线免费观看| 无码一区二区三区AV免费| 国产精品亚洲专区在线观看| 免费夜色污私人影院网站电影| 久久免费观看国产精品88av| 亚洲AV永久无码精品成人| 亚洲精品乱码久久久久久V| 日本免费高清视频| 亚洲a在线视频视频| 久久精品国产亚洲av品善| 在线免费观看国产视频| 亚洲2022国产成人精品无码区| 久久久久久AV无码免费网站下载| 又色又污又黄无遮挡的免费视| 亚洲精品国产高清在线观看| 国产99视频精品免费观看7| 亚洲最大无码中文字幕| 久久w5ww成w人免费| 亚洲一区二区三区免费| 亚洲三级高清免费| 中文字幕免费高清视频| 亚洲免费中文字幕| h在线观看视频免费网站| av在线亚洲欧洲日产一区二区| 久久精品无码免费不卡| 国产一精品一aⅴ一免费| 亚洲最大福利视频| 免费国产a国产片高清| 成人性做爰aaa片免费看| 成人亚洲网站www在线观看| 亚洲色大成网站www尤物| 亚洲精品无码日韩国产不卡?V| 看亚洲a级一级毛片| 国产AV无码专区亚洲精品| 国产在线观看免费视频软件 |