<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>多线程 on My Blog</title>
    <link>http://localhost:1313/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/</link>
    <description>Recent content from My Blog</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    
    <managingEditor>3453434429@qq.com (ArenBase)</managingEditor>
    <webMaster>3453434429@qq.com (ArenBase)</webMaster>
    
    <copyright>本博客所有文章除特别声明外，均采用 BY-NC-SA 许可协议。转载请注明出处！</copyright>
    
    <lastBuildDate>Fri, 05 Jun 2026 00:00:00 +0000</lastBuildDate>
    
    
    <atom:link href="http://localhost:1313/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/index.xml" rel="self" type="application/rss&#43;xml" />
    

    
    

    <item>
      <title>继承 Thread 类和实现 Runnable 接口的区别</title>
      <link>http://localhost:1313/post/%E7%BB%A7%E6%89%BF-thread-%E7%B1%BB%E5%92%8C%E5%AE%9E%E7%8E%B0-runnable-%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%8C%BA%E5%88%AB/</link>
      <pubDate>Fri, 05 Jun 2026 00:00:00 &#43;0000</pubDate>
      <author>3453434429@qq.com (ArenBase)</author>
      <guid>http://localhost:1313/post/%E7%BB%A7%E6%89%BF-thread-%E7%B1%BB%E5%92%8C%E5%AE%9E%E7%8E%B0-runnable-%E6%8E%A5%E5%8F%A3%E7%9A%84%E5%8C%BA%E5%88%AB/</guid>
      <description>
        <![CDATA[<h1>继承 Thread 类和实现 Runnable 接口的区别</h1><p>作者：ArenBase（3453434429@qq.com）</p>
        
          <p>在 Java 中，<strong>继承 <code>Thread</code> 类</strong>和<strong>实现 <code>Runnable</code> 接口</strong>是两种经典的多线程实现方式。它们本质上都是通过 <code>Thread</code> 类来执行线程，但设计理念和适用场景有明显区别。</p>
<h2 id="核心区别总结">
<a class="header-anchor" href="#%e6%a0%b8%e5%bf%83%e5%8c%ba%e5%88%ab%e6%80%bb%e7%bb%93"></a>
核心区别总结
</h2><table>
  <thead>
      <tr>
          <th>对比维度</th>
          <th>继承 <code>Thread</code> 类</th>
          <th>实现 <code>Runnable</code> 接口</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>资源共享</strong></td>
          <td>较难实现（需要共享静态变量或外部对象）</td>
          <td>天然支持多个线程共享同一个 <code>Runnable</code> 实例</td>
      </tr>
      <tr>
          <td><strong>灵活性</strong></td>
          <td>低（Java单继承限制）</td>
          <td>高（可以继承其他类）</td>
      </tr>
      <tr>
          <td><strong>代码与逻辑分离</strong></td>
          <td>未分离（线程创建和任务代码耦合）</td>
          <td>已分离（线程和任务解耦）</td>
      </tr>
      <tr>
          <td><strong>线程池支持</strong></td>
          <td>不推荐使用（<code>Thread</code> 对象不能被重用）</td>
          <td>推荐使用（<code>Runnable</code> 或 <code>Callable</code> 提交给线程池）</td>
      </tr>
      <tr>
          <td><strong>适用场景</strong></td>
          <td>简单、临时、不需要共享数据的线程</td>
          <td>复杂、需要共享资源、或已有父类的场景</td>
      </tr>
  </tbody>
</table>
<h2 id="详细对比与示例">
<a class="header-anchor" href="#%e8%af%a6%e7%bb%86%e5%af%b9%e6%af%94%e4%b8%8e%e7%a4%ba%e4%be%8b"></a>
详细对比与示例
</h2><h3 id="1-资源共享能力">
<a class="header-anchor" href="#1-%e8%b5%84%e6%ba%90%e5%85%b1%e4%ba%ab%e8%83%bd%e5%8a%9b"></a>
1. 资源共享能力
</h3><p><strong>继承 <code>Thread</code> 类</strong>：每个线程对象拥有自己独立的成员变量副本，要共享数据通常需要 <code>static</code> 变量或传递公共对象。</p>
        
        <hr><p>本文2026-06-05首发于<a href='http://localhost:1313/'>My Blog</a>，最后修改于2026-06-05</p>]]>
      </description>
      
        <category>Java</category>
      
    </item>
    
  </channel>
</rss>
