Java Object类

Object Structure

image.png

1,线程同步方法

1)notify()方法

  • 唤醒在当前对象监视器上等待的单个线程。Wakes up a single thread that is waiting on this object's monitor.
  • 必须是对象监听器的拥有者线程才能执行notify方法。This method should only be called by a thread that is the owner of this object's monitor.
  • 成为对象监听器拥有者的3中方法。A thread becomes the owner of the object's monitor in one of three ways
    执行该对象的synchronized实例方法By executing a synchronized instance method of that object.
    执行该对象的synchronized语句By executing the body of a synchronized statement that synchronizes on the object.
    执行类的synchronized静态方法executing a synchronized static method of that class.
    2)notifyAll()方法
    唤醒在当前对象监听器上等待的所有线程。Wakes up all threads that are waiting on this object's monitor.
    必须是对象监听器的拥有者线程才能执行notify方法。This method should only be called by a thread that is the owner of this object's monitor.
    3)wait方法
    导致当前线程等待,直到其他线程调用notify或者notifyAll方法。Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

2,其他方法

1)hashCode方法Returns a hash code value for the object.
对hash表结构提供支持。例如HashMap、hashTable等。This method is supported for the benefit of hash tables such as those provided by HashMap.
2)toString方法
默认return getClass().getName() + "@" + Integer.toHexString(hashCode());
3)equals方法
默认比较两个引用是否相同。return (this == obj);
4)public final native Class<?> getClass();方法。
获取对象的类类型。

3,垃圾回收

1)finalize方法
GC在回收对象之前调用该方法。Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,448评论 0 10
  • 甲醛,一直被称为室内污染的“头号杀手”,对人体健康的影响非常大。而在家居市场上,打着“零甲醛”旗号的产品比比皆是,...
    心悦热点资讯阅读 193评论 0 0
  • 我想和你虚度时光 比如低头看鱼 比如把茶杯留在桌子上离开 浪费它们好看的阴影 我还想连落日一起浪费 比如散步 一直...
    姗姗来迟2017阅读 132评论 0 1
  • 假如你不够快乐 也不要把眉头深锁 人生本来短暂 为什么 还要栽培苦涩 打开尘封的门窗 让阳光雨露洒遍每个角落 走向...
    夜已深不如独醉阅读 245评论 0 0
  • 其实,我脾气很暴躁是因为我肝气郁结。可不可以自我克服这个脾气暴躁呢?不知道。因为我今天早上,就是因为一只被子里的蚊...
    夜深月明阅读 258评论 0 0