diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE new file mode 100644 index 00000000..f556da01 --- /dev/null +++ b/.github/ISSUE_TEMPLATE @@ -0,0 +1,13 @@ +**在提交issue之前请回答以下问题,谢谢!** + +> 建议首先查看是否已经有类似的 Issues (提交时可删除该提示) + +### 你使用的是哪个版本 + +### 预期结果 + +### 实际结果 + +### 重现结果的步骤 + +### 其他相关信息 \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE new file mode 100644 index 00000000..28a38058 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE @@ -0,0 +1,16 @@ +如果是文字类 PR,请按照 [中文排版指北](https://github.com/sparanoid/chinese-copywriting-guidelines) 进行编写(提交时可删除该提示)。 + +**What kind of change does this PR introduce?** (check at least one) + +- [ ] Bugfix +- [ ] Feature +- [ ] Code style update +- [ ] Refactor +- [ ] Build-related changes +- [ ] Other, please describe: + + +**The description of the PR:** + + +**Other information:** \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..9396aad0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: java + +install: mvn install -DskipTests=true -Dmaven.javadoc.skip=true +script: mvn -DskipTests=true clean install + + +branches: + only: + - master \ No newline at end of file diff --git a/79884.log b/79884.log new file mode 100644 index 00000000..3b791505 --- /dev/null +++ b/79884.log @@ -0,0 +1,93 @@ +2018-03-06 23:11:05 +Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode): + +"Attach Listener" #15 daemon prio=9 os_prio=31 tid=0x00007ffd7b08b800 nid=0x1407 waiting on condition [0x0000000000000000] + java.lang.Thread.State: RUNNABLE + +"DestroyJavaVM" #14 prio=5 os_prio=31 tid=0x00007ffd7b001800 nid=0x1c03 waiting on condition [0x0000000000000000] + java.lang.Thread.State: RUNNABLE + +"Blocked2" #13 prio=5 os_prio=31 tid=0x00007ffd7b08b000 nid=0x5503 waiting for monitor entry [0x00007000083d1000] + java.lang.Thread.State: BLOCKED (on object monitor) + at com.crossoverjie.thread.ThreadState$Blocked.run(ThreadState.java:59) + - waiting to lock <0x000000079576cd60> (a java.lang.Class for com.crossoverjie.thread.ThreadState$Blocked) + at java.lang.Thread.run(Thread.java:748) + +"Blocked1" #12 prio=5 os_prio=31 tid=0x00007ffd7b08a000 nid=0x5303 waiting on condition [0x00007000082ce000] + java.lang.Thread.State: TIMED_WAITING (sleeping) + at java.lang.Thread.sleep(Native Method) + at com.crossoverjie.thread.ThreadState$Blocked.run(ThreadState.java:59) + - locked <0x000000079576cd60> (a java.lang.Class for com.crossoverjie.thread.ThreadState$Blocked) + at java.lang.Thread.run(Thread.java:748) + +"Waiting" #11 prio=5 os_prio=31 tid=0x00007ffd7b089800 nid=0x5103 in Object.wait() [0x00007000081cb000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <0x0000000795768db0> (a java.lang.Class for com.crossoverjie.thread.ThreadState$Waiting) + at java.lang.Object.wait(Object.java:502) + at com.crossoverjie.thread.ThreadState$Waiting.run(ThreadState.java:42) + - locked <0x0000000795768db0> (a java.lang.Class for com.crossoverjie.thread.ThreadState$Waiting) + at java.lang.Thread.run(Thread.java:748) + +"TimeWaiting" #10 prio=5 os_prio=31 tid=0x00007ffd7b82c800 nid=0x4f03 waiting on condition [0x00007000080c8000] + java.lang.Thread.State: TIMED_WAITING (sleeping) + at java.lang.Thread.sleep(Native Method) + at com.crossoverjie.thread.ThreadState$TimeWaiting.run(ThreadState.java:27) + at java.lang.Thread.run(Thread.java:748) + +"Monitor Ctrl-Break" #9 daemon prio=5 os_prio=31 tid=0x00007ffd7a97e000 nid=0x4d03 runnable [0x0000700007fc5000] + java.lang.Thread.State: RUNNABLE + at java.net.PlainSocketImpl.socketAccept(Native Method) + at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:409) + at java.net.ServerSocket.implAccept(ServerSocket.java:545) + at java.net.ServerSocket.accept(ServerSocket.java:513) + at com.intellij.rt.execution.application.AppMain$1.run(AppMain.java:79) + at java.lang.Thread.run(Thread.java:748) + +"Service Thread" #8 daemon prio=9 os_prio=31 tid=0x00007ffd7a837800 nid=0x4903 runnable [0x0000000000000000] + java.lang.Thread.State: RUNNABLE + +"C1 CompilerThread2" #7 daemon prio=9 os_prio=31 tid=0x00007ffd7b030800 nid=0x4703 waiting on condition [0x0000000000000000] + java.lang.Thread.State: RUNNABLE + +"C2 CompilerThread1" #6 daemon prio=9 os_prio=31 tid=0x00007ffd7b029800 nid=0x4503 waiting on condition [0x0000000000000000] + java.lang.Thread.State: RUNNABLE + +"C2 CompilerThread0" #5 daemon prio=9 os_prio=31 tid=0x00007ffd7a813800 nid=0x4303 waiting on condition [0x0000000000000000] + java.lang.Thread.State: RUNNABLE + +"Signal Dispatcher" #4 daemon prio=9 os_prio=31 tid=0x00007ffd7a839000 nid=0x4103 runnable [0x0000000000000000] + java.lang.Thread.State: RUNNABLE + +"Finalizer" #3 daemon prio=8 os_prio=31 tid=0x00007ffd7b00b800 nid=0x3103 in Object.wait() [0x00007000078b0000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <0x0000000795588ec8> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) + - locked <0x0000000795588ec8> (a java.lang.ref.ReferenceQueue$Lock) + at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164) + at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209) + +"Reference Handler" #2 daemon prio=10 os_prio=31 tid=0x00007ffd7a800800 nid=0x2f03 in Object.wait() [0x00007000077ad000] + java.lang.Thread.State: WAITING (on object monitor) + at java.lang.Object.wait(Native Method) + - waiting on <0x0000000795586b68> (a java.lang.ref.Reference$Lock) + at java.lang.Object.wait(Object.java:502) + at java.lang.ref.Reference.tryHandlePending(Reference.java:191) + - locked <0x0000000795586b68> (a java.lang.ref.Reference$Lock) + at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153) + +"VM Thread" os_prio=31 tid=0x00007ffd7a01a800 nid=0x2d03 runnable + +"GC task thread#0 (ParallelGC)" os_prio=31 tid=0x00007ffd7b005800 nid=0x2503 runnable + +"GC task thread#1 (ParallelGC)" os_prio=31 tid=0x00007ffd7b006000 nid=0x2703 runnable + +"GC task thread#2 (ParallelGC)" os_prio=31 tid=0x00007ffd7b006800 nid=0x2903 runnable + +"GC task thread#3 (ParallelGC)" os_prio=31 tid=0x00007ffd7b808000 nid=0x2b03 runnable + +"VM Periodic Task Thread" os_prio=31 tid=0x00007ffd7a03e000 nid=0x4b03 waiting on condition + +JNI global references: 21 + diff --git a/MD/ArrayList.md b/MD/ArrayList.md index 06271b12..11bb2ae1 100644 --- a/MD/ArrayList.md +++ b/MD/ArrayList.md @@ -2,7 +2,7 @@ ## ArrayList -`ArrayList` 实现于 `List`、`RandomAccess` 接口。可以插入空数据,也支持随机随机访问。 +`ArrayList` 实现于 `List`、`RandomAccess` 接口。可以插入空数据,也支持随机访问。 `ArrayList `相当于动态数据,其中最重要的两个属性分别是: `elementData` 数组,以及 `size` 大小。 @@ -55,10 +55,69 @@ 由此可见 `ArrayList` 的主要消耗是数组扩容以及在指定位置添加数据,在日常使用时最好是指定大小,尽量减少扩容。更要减少在指定位置插入数据的操作。 +### 序列化 + +由于 ArrayList 是基于动态数组实现的,所以并不是所有的空间都被使用。因此使用了 `transient` 修饰,可以防止被自动序列化。 + +```java +transient Object[] elementData; +``` + +因此 ArrayList 自定义了序列化与反序列化: + +```java + private void writeObject(java.io.ObjectOutputStream s) + throws java.io.IOException{ + // Write out element count, and any hidden stuff + int expectedModCount = modCount; + s.defaultWriteObject(); + + // Write out size as capacity for behavioural compatibility with clone() + s.writeInt(size); + + // Write out all elements in the proper order. + //只序列化了被使用的数据 + for (int i=0; i