发布于 2014-10-24 04:53:32 | 502 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Sogou 搜狗

搜狗是搜狐公司的旗下子公司,于2004年8月3日推出,目的是增强搜狐网的搜索技能,主要经营搜狐公司的搜索业务。在搜索业务的同时,也推出搜狗高速浏览器、搜狗输入法、免费邮箱、企业邮箱等业务。


昨天上午笔试的,隔了一天才来写,好多忘了。。

选择题:

有给二叉树先序遍历、后续遍历,让求中序遍历的题。

问Math.round(-8.5)返回什么类型?

这题果然答错了,回来试了一下答案是long -8。

问答题:

给了一个用户注册消费的程序让分析有什么问题

程序还记得,有空敲上来。

将两个有序数组合并

这个就是归并的最后一步嘛。

用线程编程实现生产者消费者模式

首先贴上线程编程的方法

 

  1. <span style="color:#006600;">public class Drop {  
  2.     // Message sent from producer  
  3.     // to consumer.  
  4.     private String message;  
  5.     // True if consumer should wait  
  6.     // for producer to send message,  
  7.     // false if producer should wait for  
  8.     // consumer to retrieve message.  
  9.     private boolean empty = true;  
  10.   
  11.     public synchronized String take() {  
  12.         // Wait until message is  
  13.         // available.  
  14.         while (empty) {  
  15.             try {  
  16.                 wait();  
  17.             } catch (InterruptedException e) {}  
  18.         }  
  19.         // Toggle status.  
  20.         empty = true;  
  21.         // Notify producer that  
  22.         // status has changed.  
  23.         notifyAll();  
  24.         return message;  
  25.     }  
  26.   
  27.     public synchronized void put(String message) {  
  28.         // Wait until message has  
  29.         // been retrieved.  
  30.         while (!empty) {  
  31.             try {   
  32.                 wait();  
  33.             } catch (InterruptedException e) {}  
  34.         }  
  35.         // Toggle status.  
  36.         empty = false;  
  37.         // Store message.  
  38.         this.message = message;  
  39.         // Notify consumer that status  
  40.         // has changed.  
  41.         notifyAll();  
  42.     }  
  43. }</span>  

 

  1. <span style="color:#006600;">import java.util.Random;  
  2.   
  3. public class Producer implements Runnable {  
  4.     private Drop drop;  
  5.   
  6.     public Producer(Drop drop) {  
  7.         this.drop = drop;  
  8.     }  
  9.   
  10.     public void run() {  
  11.         String importantInfo[] = {  
  12.             "Mares eat oats",  
  13.             "Does eat oats",  
  14.             "Little lambs eat ivy",  
  15.             "A kid will eat ivy too"  
  16.         };  
  17.         Random random = new Random();  
  18.   
  19.         for (int i = 0;  
  20.              i < importantInfo.length;  
  21.              i++) {  
  22.             drop.put(importantInfo[i]);  
  23.             try {  
  24.                 Thread.sleep(random.nextInt(5000));  
  25.             } catch (InterruptedException e) {}  
  26.         }  
  27.         drop.put("DONE");  
  28.     }  
  29. }</span>  

 

  1. <span style="color:#006600;">import java.util.Random;  
  2.   
  3. public class Consumer implements Runnable {  
  4.     private Drop drop;  
  5.   
  6.     public Consumer(Drop drop) {  
  7.         this.drop = drop;  
  8.     }  
  9.   
  10.     public void run() {  
  11.         Random random = new Random();  
  12.         for (String message = drop.take();  
  13.              ! message.equals("DONE");  
  14.              message = drop.take()) {  
  15.             System.out.format("MESSAGE RECEIVED: %s%n", message);  
  16.             try {  
  17.                 Thread.sleep(random.nextInt(5000));  
  18.             } catch (InterruptedException e) {}  
  19.         }  
  20.     }  
  21. }</span>  

 

  1. <span style="color:#006600;">public class ProducerConsumerExample {  
  2.     public static void main(String[] args) {  
  3.         Drop drop = new Drop();  
  4.         (new Thread(new Producer(drop))).start();  
  5.         (new Thread(new Consumer(drop))).start();  
  6.     }  
  7. }</span> 


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务