{"id":542,"date":"2023-09-16T16:08:01","date_gmt":"2023-09-16T08:08:01","guid":{"rendered":""},"modified":"2023-09-17T00:41:54","modified_gmt":"2023-09-16T16:41:54","slug":"%e5%9c%a8android%e4%b8%ad%e5%ae%9e%e7%8e%b0%e5%a4%9a%e7%ba%bf%e7%a8%8b%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/mushiming.com\/542.html","title":{"rendered":"\u5728Android\u4e2d\u5b9e\u73b0\u591a\u7ebf\u7a0b\u540c\u6b65"},"content":{"rendered":"

 1. java\u4e2d\u5bf9\u591a\u7ebf\u7a0b\u8bbf\u95ee\u63a7\u5236\u53ef\u4f7f\u7528\u5173\u952e\u5b57synchronized
\n
\u4e0b\u9762\u5c06\u4ee5
\nProducer Consumer\u6a21\u578b\u4ecb\u7ecdandroid\u4e2d\u7ebf\u7a0b\u540c\u6b65\u7684\u4f7f\u7528\u3002<\/p>\n

\u6b65\u9aa4\uff1a
\u5efa\u7acb\u4e00android project\uff0c
\u4fee\u6539main activity\u5982\u4e0b\uff1a<\/p>\n

\u4ee3\u7801\uff1a<\/p>\n

package com.test.thread;<\/p>\n

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;<\/p>\n

public class MultiThread extends Activity {
\n
   
    private static final String MultiThread_ACTIVITY_TAG = \"MultiThread_TAG\";
    \/** Called when the activity is first created. *\/
    @Override
    public void onCreate(Bundle savedInstanceState) {
\n
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        CubbyHole c = new CubbyHole();
        Producer p1 = new Producer(c, 1);
        Consumer c1 = new Consumer(c, 1);
       
        p1.start();
        c1.start();
        <\/small><\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Android\u4e2d\u5b9e\u73b0\u591a\u7ebf\u7a0b\u540c\u6b651.java\u4e2d\u5bf9\u591a\u7ebf\u7a0b\u8bbf\u95ee\u63a7\u5236\u53ef\u4f7f\u7528\u5173\u952e\u5b57synchronized\u4e0b\u9762\u5c06\u4ee5ProducerConsumer\u6a21\u578b\u4ecb\u7ecdandroid\u4e2d\u7ebf...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/542"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=542"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/542\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}