提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • 曹阳

    54人对此回答表示赞同


    /** This class demonstrates how you might use the Rect class */
    public class RectTest {
    public static void main(String[] args) {
    Rect r1 = new Rect(1, 1, 4, 4); // Create Rect objects
    Rect r2 = new Rect(2, 3, 5, 6);
    Rect u = r1.union(r2); // Invoke Rect methods
    Rect i = r2.intersection(r1);

    if (u.isInside(r2.x1, r2.y1)) // Use Rect fields and invoke a method
    System.out.println("(" + r2.x1 + "," + r2.y1 +
    ") is inside the union");

    // These lines implicitly call the Rect.toString() method
    System.out.println(r1 + " union " + r2 + " = " + u);
    System.out.println(r1 + " intersect " + r2 + " = " + i);
    }
    }

    ******************************************************************
    关于死锁的。
    /**
    * This is a demonstration of how NOT to write multi-threaded programs.
    * It is a program that purposely causes deadlock between two threads that
    * are both trying to acquire locks for the same two resources.
    * To avoid this sort of deadlock when locking multiple resources, all threads
    * should always acquire their locks in the same order.
    **/
    public class Deadlock {
    public static void main(String[] args) {
    // These are the two resource objects we'll try to get locks for
    final Object resource1 = "resource1";
    final Object resource2 = "resource2";
    // Here's the first thread. It tries to lock resource1 then resource2
    Thread t1 = new Thread() {
    public void run() {
    // Lock resource 1
    synchronized(resource1) {
    System.out.println("Thread 1: locked resource 1");

    // Pause for a bit, simulating some file I/O or
    // something. Basically, we just want to give the
    // other thread a chance to run. Threads and deadlock
    // are asynchronous things, but we're trying to force
    // deadlock to happen here...
    try { Thread.sleep(50); }
    catch (InterruptedException e) {}

    // Now wait 'till we can get a lock on resource 2
    synchronized(resource2) {
    System.out.println("Thread 1: locked resource 2");
    }
    }
    }
    };

    展开
    54
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • betty

    54人对此回答表示赞同

    网上有好多搜的.
    展开
    54
    0回复
    发布于 8年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部