⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch04s02.html

📁 优秀的java程序开发软件方式与方法,对大家开发程序的时候有指导性帮助
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html><head>      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">   <title>2.&nbsp;&#22312;Java&#19978;&#23454;&#29616;Continuation&#65306;&#22522;&#20110;stack&#27861;</title><link rel="stylesheet" href="html.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.69.1"><link rel="start" href="index.html" title="Java&#32593;&#32476;&#31243;&#24207;&#21592;&#30475;Continuation"><link rel="up" href="ch04.html" title="Chapter&nbsp;4.&nbsp;Continuation&#30340;&#23454;&#29616;"><link rel="prev" href="ch04s01.html" title="1.&nbsp;Continuation&#30340;&#24120;&#35268;&#23454;&#29616;&#26041;&#27861;"><link rel="next" href="ch04s03.html" title="3.&nbsp;&#22312;Java&#19978;&#23454;&#29616;Continuation&#65306;&#22522;&#20110;heap&#27861;"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2.&nbsp;&#22312;Java&#19978;&#23454;&#29616;Continuation&#65306;&#22522;&#20110;stack&#27861;</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s01.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;4.&nbsp;Continuation&#30340;&#23454;&#29616;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ch04s03.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e542"></a>2.&nbsp;&#22312;Java&#19978;&#23454;&#29616;Continuation&#65306;&#22522;&#20110;stack&#27861;</h2></div></div></div><p>&#31572;&#26696;&#26159;&#32943;&#23450;&#30340;&#12290;</p><p>&#39318;&#20808;&#25105;&#20204;&#20171;&#32461;&#19968;&#20010;&#19981;&#23436;&#25972;&#30340;&#35299;&#27861;&#12290;&#22914;&#26524;&#25105;&#20204;&#25918;&#24323;&#23545;&#22238;&#36864;&#38190;&#30340;&#25903;&#25345;&#65292;&#37027;&#20040;&#25105;&#20204;&#23601;&#19981;&#38656;&#35201;&#25972;&#20010;continuation&#65292;&#22240;&#20026;&#21482;&#35201;&#26377;coroutine&#23601;&#36275;&#22815;&#25903;&#25345;call/answer&#20102;&#12290;&#20174;&#26576;&#31181;&#24847;&#20041;&#19978;&#35762;&#65292;call/answer&#27604;&#22238;&#36864;&#38190;&#30340;&#25903;&#25345;&#37325;&#35201;&#65292;&#22240;&#20026;&#25105;&#20204;&#26222;&#36941;&#19978;&#24050;&#32463;&#25509;&#21463;&#20102;&#32593;&#32476;&#31243;&#24207;&#19981;&#33021;&#24456;&#22909;&#22320;&#25903;&#25345;&#22238;&#36864;&#36825;&#20010;&#20107;&#23454;&#12290;&#32780;&#22914;&#21069;&#25991;&#25152;&#35828;&#65292;coroutine&#21487;&#20197;&#29992;&#20004;&#20010;&#32447;&#31243;&#26469;&#27169;&#25311;&#12290;&#25152;&#20197;&#65292;&#22914;&#26524;&#25105;&#20204;&#19981;&#20171;&#24847;&#29992;&#24456;&#22810;&#32447;&#31243;&#65292;&#25105;&#20204;&#21487;&#20197;&#23601;&#21487;&#20197;&#29992;&#26222;&#36890;&#30340;Java&#23454;&#29616;call/answer&#12290;&#24403;&#28982;&#65292;&#25805;&#20316;&#31995;&#32479;&#21487;&#33021;&#19981;&#20250;&#21916;&#27426;web server&#29992;&#25104;&#21315;&#19978;&#19975;&#20010;&#32447;&#31243;&#65292;&#20294;&#26159;&#65292;&#27604;&#26041;&#35828;&#20570;&#19968;&#33324;&#30340;&#20225;&#19994;&#20869;&#37096;&#32593;&#32476;&#65292;&#36825;&#20010;&#26041;&#27861;&#26159;&#24456;&#21487;&#34892;&#30340;&#65292;&#32780;&#19988;&#20225;&#19994;&#20869;&#37096;&#32593;&#32476;&#24448;&#24448;&#27491;&#26159;&#36923;&#36753;&#26368;&#22797;&#26434;&#30340;&#32593;&#32476;&#31243;&#24207;&#12290;</p><p>&#65288;&#27880;&#24847;C# 2.0&#25552;&#20379;&#20102;&#23545;coroutine&#30340;&#30452;&#25509;&#25903;&#25345;&#65292;&#26080;&#39035;&#29992;&#22810;&#32447;&#31243;&#27169;&#25311;&#12290;&#65289;</p><p>&#21478;&#19968;&#26041;&#38754;&#65292;&#22914;&#26524;&#35201;&#22312;Java&#19978;&#25903;&#25345;&#30495;&#27491;&#30340;continuation&#65292;&#20294;&#26159;&#21448;&#19981;&#33021;&#20462;&#25913;JVM&#65292;&#37027;&#20040;&#25105;&#20204;&#21482;&#33021;&#20174;Java&#28304;&#20195;&#30721;&#25110;bytecode&#19978;&#30528;&#25163;&#65292;&#29992;&#36825;&#20004;&#32773;&#23454;&#29616;&#30340;&#21306;&#21035;&#19981;&#31639;&#22826;&#22823;&#65292;&#20027;&#35201;&#19981;&#21516;&#22312;&#20110;Java bytecode&#25903;&#25345;goto&#21629;&#20196;&#65292;&#32780;Java&#21017;&#19981;&#25903;&#25345;&#12290;&#20462;&#25913;Java bytecode&#65292;&#36825;&#26089;&#24050;&#19981;&#26159;&#20160;&#20040;&#26032;&#25216;&#26415;&#20102;&#65292;&#22312;Java&#19978;&#23454;&#29616;&#24456;&#22810;&#21035;&#30340;&#26032;&#21151;&#33021;&#65292;&#22914;AOP&#31561;&#65292;&#20063;&#21516;&#26679;&#26159;&#37319;&#29992;&#20462;&#25913;bytecode&#30340;&#26041;&#27861;&#12290;&#25105;&#20204;&#19979;&#38754;&#20171;&#32461;&#19968;&#20010;&#29992;&#28304;&#20195;&#30721;&#25903;&#25345;continuation&#30340;&#20363;&#23376;&#65292;&#21516;&#26679;&#30340;&#26041;&#27861;&#20063;&#21487;&#20197;&#29992;&#22312;bytecode&#19978;&#12290;</p><p>&#39318;&#20808;&#65292;&#25105;&#20204;&#27880;&#24847;&#21040;&#29992;&#22522;&#20110;heap&#30340;&#26041;&#27861;&#24456;&#19981;&#23481;&#26131;&#65292;&#22240;&#20026;JVM&#19968;&#23450;&#20250;&#32500;&#25345;&#19968;&#20010;stack&#12290;&#38500;&#38750;&#25105;&#20204;&#33021;&#20462;&#25913;JVM&#65292;&#21542;&#21017;&#25105;&#20204;&#27809;&#27861;&#25226;&#36825;&#20010;stack&#25918;&#21040;heap&#20013;&#21435;&#12290;OK&#65292;&#20854;&#23454;&#36825;&#37324;&#25105;&#25746;&#20102;&#20010;&#35854;&#65292;&#25105;&#20204;&#36824;&#26159;&#26377;&#21150;&#27861;&#29992;&#22522;&#20110;heap&#30340;&#26041;&#24335;&#65292;&#24403;&#28982;&#36825;&#24182;&#19981;&#23481;&#26131;&#12290;&#25105;&#20204;&#22312;&#26412;&#31456;&#26368;&#21518;&#20250;&#30475;&#21040;&#19968;&#20010;&#36825;&#26679;&#30340;&#20363;&#23376;&#12290;</p><p>&#25105;&#20204;&#29616;&#22312;&#30340;&#36825;&#20010;&#20363;&#23376;&#29992;&#30340;&#26159;&#27604;&#36739;&#23481;&#26131;&#30340;&#22522;&#20110;stack&#30340;&#26041;&#27861;&#12290;&#22914;&#26524;&#25105;&#20204;&#29992;&#22522;&#20110;stack&#30340;&#26041;&#27861;&#65292;&#37027;&#20040;&#25105;&#20204;&#38656;&#35201;&#33021;&#22815;&#22797;&#21046;stack&#12290;&#36825;&#22312;JVM&#20013;&#26159;&#19981;&#21487;&#33021;&#30340;&#65292;&#22240;&#20026;JVM&#22522;&#20110;&#23433;&#20840;&#29702;&#30001;&#19981;&#35753;&#25105;&#20204;&#23519;&#30475;stack&#30340;&#20869;&#23481;&#12290;&#21834;&#65311;&#20160;&#20040;&#65311;&#21035;&#30528;&#24613;&#65292;&#20854;&#23454;&#36825;&#37324;&#25105;&#21448;&#25746;&#20102;&#20010;&#24908;&#12290;&#29992;&#19968;&#28857;&#23567;&#25216;&#24039;&#25105;&#20204;&#23601;&#33021;&#22797;&#21046;&#21644;&#24674;&#22797;stack&#12290;&#26469;&#30475;&#20363;&#23376;&#65306;</p><pre class="programlisting">public class DuplicateStack {    public static void parent() {        System.out.println("Parent: 1");        child(1);        System.out.println("Parent: 2");        child(2);        System.out.println("Parent: 3");    }    public static void child(int i) {        System.out.println("Child: i = " + i);        if (i == 2) {            // record stack //        }        System.out.println("Child exits.");    }    public static void main(String[] args) {        parent();    }}</pre><p>&#19978;&#38754;&#30340;&#20363;&#23376;&#27809;&#26377;&#23454;&#29616;// record stack //&#25805;&#20316;&#65292;&#25105;&#20204;&#23558;&#22312;&#21518;&#38754;&#25226;&#36825;&#37096;&#20998;&#34917;&#19978;&#12290;&#22312;&#23454;&#29616;&#35813;&#25805;&#20316;&#20043;&#21069;&#65292;&#24744;&#19968;&#23450;&#33021;&#22815;&#30475;&#20986;&#27492;&#20363;&#23376;&#30340;&#36755;&#20986;&#20026;&#65306;</p><pre class="screen">Parent: 1Child: i = 1Child exits.Parent: 2Child: i = 2Child exits.Parent: 3</pre><p>&#19979;&#38754;&#25105;&#20204;&#30340;Java&#31243;&#24207;&#21644;&#19978;&#38754;&#30340;&#26159;&#31561;&#20215;&#30340;&#65292;&#20294;&#26159;&#23427;&#23454;&#29616;&#20102;// record stack //&#25805;&#20316;&#12290;&#20026;&#20102;&#23637;&#31034;&#36825;&#20010;&#21151;&#33021;&#65292;&#25105;&#20204;&#22312;main()&#37324;&#35753;parent()&#20989;&#25968;&#36820;&#22238;&#22810;&#27425;&#65306;</p><pre class="programlisting">import java.util.Stack;class RecordStackException extends RuntimeException {    RuntimeStack rs;        public RecordStackException(RuntimeStack rs) {        this.rs = rs;    }    public RuntimeStack getRuntimeStack() {        return rs;    }}class RuntimeStack implements Cloneable {    private Stack countStack = new Stack();    private Stack varStack = new Stack();        public void pushCount(int c) {        countStack.push(new Integer(c));     }    public int popCount() {         return ((Integer) countStack.pop()).intValue();     }     public void pushVar(Object v) {        varStack.push(v);    }    public Object popVar() {        return varStack.pop();    }    /* convenience methods */    public void pushInt(int i) {        pushVar(new Integer(i));    }    public int popInt() {        return ((Integer) popVar()).intValue();    }        public Object clone() {        RuntimeStack s = new RuntimeStack();        s.countStack = (Stack) countStack.clone();        s.varStack = (Stack) varStack.clone();        return s;    }}public class DuplicateStack {    static void parentRecordStack(RuntimeStack s, int c) {        s.pushCount(c);        throw new RecordStackException(s);    }        static void parent(RuntimeStack s) {        int count = 0;        if (s != null) {            count = s.popCount();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -