article search result of 'worker' : 1

  1. 2012.11.15 [AS3 Worker] Thread Test (2920)

[AS3 Worker] Thread Test

 

드디어 As3 에 Worker 라는것이 생겼다.

바로 Thread 이다.

하지만 , 방법이 조금 지저분 하다.

실행되고 있는 바이트 코드를 그대로 복제하여 ,백그라운드에서 실행하고 그 결과를 메시지 체널 형태로 주고 받는다.

정확한 Thread 의 개념 보다는 .NET 의 BackgroundWorker 쯤으로 생각하면 될듯하고

쓰레드를 직접실행할 클래스 형태가 필요하다.

 

아래의 ThreadManager 는 구차한 Worker 생성과정을 미리 생성하고 Thread 객체를 관리하는 매니저 역할이다.

또하나의 Worker1 클래스는 쓰레드 개체가 생성하게될 , 즉 쓰레드가 수행할 내용이다.

아래의 실험은 같은 개체를 동시에 실행 하였을때 쓰레드 블럭킹이 발생하는지 실험하는 코드이다.

 

* ThreadManager

 
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;
    
    import jjongun.threadWorker.Thread;
    import jjongun.threadWorker.ThreadEvent;
    import jjongun.threadWorker.ThreadManager;
    
    public class TestThread3 extends Sprite
    {
        private var thread1 : Thread;
        private var thread2 : Thread;
        public function TestThread3()
        {
            ThreadManager.Init(this.stage);
            
            thread1 = ThreadManager.getInst().createThread(Work1);
            thread2 = ThreadManager.getInst().createThread(Work1);
            
            thread1.addEventListener(ThreadEvent.RECEIVE , receive);
            thread2.addEventListener(ThreadEvent.RECEIVE , receive);
            
            thread1.start();
            thread2.start();
            
            stage.addEventListener(KeyboardEvent.KEY_UP , stageKup);
        }
        
        protected function stageKup(e:KeyboardEvent):void
        {
            if(e.keyCode == Keyboard.A)
            {
                trace("A");
                thread1.send(Work1.F1);
            }
            else if(e.keyCode == Keyboard.S)
            {
                trace("S");
                thread2.send(Work1.F2);
            }
        }
        
        protected function receive(e:ThreadEvent):void
        {
            if(e.currentTarget == thread1)
            {
                trace(e.receiveData);
            }
            else if(e.currentTarget == thread2)
            {
                trace(e.receiveData);
            }
        }
    }
}

 

 

 

 

package
{
    import flash.utils.getTimer;
    
    import jjongun.threadWorker.AbsThreadWorker;
    
    public class Work1 extends AbsThreadWorker
    {
        public function Work1()
        {
            super();
        }
        
        public static const F1 : String = "F1";
        public static const F2 : String = "F2";
        protected override function threadMessage(command:*):void
        {
            trace("command " , command);
            if(command == F1)
            {
                f1();
            }
            else if(command == F2)
            {
                f2();
            }
        }
        
    
        
        private function f1():void
        {
            trace("start _ f1 " , getTimer());
            
            var b : Boolean = true;
            var cur : Number = getTimer();
            while(b)
            {
                if(getTimer() - cur > 3000)
                {
                    b = false;
                }
            }
            
            trace("end _ f1" , getTimer());
        }
        
        private function f2():void
        {
            trace("start _ f2 " , getTimer());
            
            var b : Boolean = true;
            var cur : Number = getTimer();
            while(b)
            {
                if(getTimer() - cur > 3000)
                {
                    b = false;
                }
            }
            
            trace("end _ f2" , getTimer());
        }
    }
}

 

결과 블럭킹이 전혀 발생하지 않았고 상상했던 Thread의 역할을 충분히 수행해 주었다.

 

주의할점은 현재 시점으로 11.4 버전 -swf-version=17 만 가능하다.

혹 그 윗버전의 SDK 로 시도 해보았지만 작동이 안된다. 이유는 모른다. 버그 같다. 어도비 포럼에도 질문만 있을뿐 답이 없다.

머 ,, 곧 해결 되겠지만 , 현재 11.4 버전 만 된다. 버전 체크를 하여 수행하여야 하겠다.

 

'AS3' 카테고리의 다른 글

FLA Auto build utility for flashbuilder developer  (2) 2014.02.22
[AS3] asmx 사용하기  (87) 2013.01.12
[AS3 Worker] Thread Test  (2920) 2012.11.15
간단한 AS3 바이트 버퍼 나누기  (110) 2012.03.09
[Multitouch on 3D World]  (92) 2012.01.17
[Base64]  (282) 2011.12.19
Yamecoder 야매코더_
tags : , ,
AS3 2012. 11. 15. 23:38

댓글을 달아 주세요

  1. 이전 댓글 더보기
  2. BlogIcon 匿名 2015.04.13 19:19  수정/삭제  댓글쓰기

    방기Greetings again from the darkness. Caught a screening of this after only seeing one trailer, which had done little to spark my interest. I will issue a "chick flick" alert; however, this is a rare case of that alert not ruining a movie for guys. This is an excellent film, period.

    Director Curtis Hanson, who helmed one of my all-time favs "L.A. Confidential" brings a reality to the film that pre로료

  3. BlogIcon 匿名 2015.04.13 19:19  수정/삭제  댓글쓰기

    니상Welcome to the online store. The is a successful shoe that combined the practical applicability and fashion together. If you put on one pair of the MBT Shoes London, you will share the super feeling as though walking on the soft beach. The MBT Trainers have adapted the Massi Barefoot Technology to achieve the goal of keeping our health. Wear on everyday you can promote blood circulation, and decre드정

  4. BlogIcon 匿名 2015.04.13 19:19  수정/삭제  댓글쓰기

    일는  Fax: (86) 5410 9322



      [城市]:上海市



      系列 : 和运动和运动鞋



      联系 : (邮箱)info-china@puma



      13 Floor, XuHuiYuan Building, 1089 ZhongShan No. 2 Rd. (S.)



      设计师 : Werner Hofer



      Fax: +49 ? 9132 ? 81 ? 2246



      PUMA AG



      General Inquiries



      [地址]:上海市中二路1089号徐汇苑大厦13楼



      PUMA-WAY 1



      中国分店 : Puma的产品在、杭州、南京和西安开设Puma店铺。Puma在全国各大城市授权的零售店销售뉴야

  5. BlogIcon 匿名 2015.04.13 19:19  수정/삭제  댓글쓰기

    일려本公司是一家集设计开发、生产制造、销售为一体的电子行业科技型企业。 公司本着创新的理念,依据科学的开发技术,凭借先进的工艺,采用完善的管理模式和质量管理体系,拥有对电子产品的设计开发和创新能力。目前主要产品有LED节能灯、LED电子蜡烛、鞋服闪光灯、电子鞋灯、工艺礼品电子、精品电子、太阳能灯饰、玩具、箱包电子产品等。品种齐全形式多样,广泛应用于室内照明、家居装饰、鞋类、工艺品、精品玩具、广告促销礼品、包袋等市场。目前公司在其他电子领域正至力开发拥有自主产权及专利的产品。 公司遵循以市场为导向,以客户为中心的发展战略,秉承“以诚信为根本,以质量求生存”方针,竭诚为广大客户提供优质的产品与服务,在同等质量条件下,力求让给客户最大的利润空间,真正做到物美价廉,实现互利互惠共同发展。 主营:开发设计生产鞋灯、电子鞋灯、防水鞋灯、shoeslight、拖鞋灯、童鞋灯、布鞋灯、服饰闪灯音乐器、服饰灯、기일

  6. BlogIcon 匿名 2015.04.13 19:19  수정/삭제  댓글쓰기

    선겠It was back to the drawing board once again when Nike devised the initial designs for its Air Max “Breathe” Collection. Striped to its base first, Nike rebuilt each portion with two key goals in mind – to make it lighter and more breathable. One of the outcomes was the Air Max Light Breathe, seen here in Pure Platinum, University Red. and Team Red. Constructed through a no-sew manufacturing proces조표

  7. BlogIcon Womens Luxury Shoes 2015.04.14 04:46  수정/삭제  댓글쓰기

    지일Charlotte Premium Outlets will open July 31 in Steele Creek, and the nearly 400,00-square-foot outlet center will have 100 stores — up from the 90 planned initially.

    The mix of retailers will sell apparel and shoes, fashion accessories,Christian Louboutin Peep-Toe Pumps, leather goods, home furnishings and specialty goods.

    The outlet mall is a 50-50 joint venture between Indianapolis-based I지어

  8. BlogIcon converse θεσσαλονικη 2015.04.14 06:38  수정/삭제  댓글쓰기

    메방Will . No longer care about them , Francis took Xiaoqing hand ,all star converse αθηνα, quickly stepped forward ,autentisitet converse billig, and went about half an hour ,converse all star παπουτσια, appeared in front of a valley , a lot of people in that valley droves sat ,pa nett converse sko norge, standing,blue sko converse, keep walking . "My brother, here is really good fun ah ! They are d리예

  9. BlogIcon all star converse greece 2015.04.14 06:38  수정/삭제  댓글쓰기

    부네An unhappy look,pink gronne converse, asked some strange . "He , ah, I estimate that because of the thinking of those other spiritual fire where ? " Hook from said with a smile . "Do seniors know the location of other spiritual fire ? " Francis heard from the hook so to speak,blue converse sko billig, eyes bright, their own eyes the do not know live how old ,barn hvite converse, certainly know a l조겠

  10. BlogIcon all star converseελλαδα 2015.04.14 06:38  수정/삭제  댓글쓰기

    버가I want to think this person is dead magician . If they are , Ka Nuosi Belle child and the man stood so close , if the fight is likely to suffer first , and then you want to let the Ka Nuosi and Belle child back to the crowd ,blue converse sko billig, beating together somewhat preparedness . "Teacher, this person is likely dead magician ,converse all star αθηνα, be careful ! " Francis has not forgo히있

  11. BlogIcon φθηνά all star converse 2015.04.14 06:38  수정/삭제  댓글쓰기

    데습Francis finished ring from space come up with two bottles of immortality , a bottle of rejuvenation Dan , last gave the Bei Luota whole bottle ,converse θεσσαλονικη, a bottle of righteousness Dan , Francis refining immortality ,pink gronne converse, as long as it is used to enhance the combat effectiveness of the fight when ,παπουτσια converse all star, was supposed to his family fought the orcs ,마단

  12. BlogIcon converse ψυχικο 2015.04.14 06:38  수정/삭제  댓글쓰기

    리는While talking , while waving Staff , the ambient temperature is getting lower and lower ,converse all star ελλαδα, to the last small area it began to snow to . "Woo ... woo ... woo ... " Firefox can not be last to flee this area ,blue sko converse, would have thought that the temperature is not low so outrageous ,autentisitet converse billig, so it want to play and in front of the human good , bu그리

  13. BlogIcon converse all star αθηνα 2015.04.14 06:39  수정/삭제  댓글쓰기

    어리A bad disappear forever in this world . "Good,converse shoes greece, good ,converse all star παπουτσια, good ! Days Lingcao Well ,παπουτσια nike, the family seems to be kind of this plant ,pa nett converse sko norge, I 'll whereabouts of family refining pharmacists , and tomorrow I will give you brought ! " Ken Delin touched Francis head , very pleased , said . "Well ,converse all star παπουτσια, 스그

  14. BlogIcon blue converse sko billig 2015.04.14 06:39  수정/삭제  댓글쓰기

    히법The Xiaoqing hit say hello and walked toward the inn . When Francis ,Salg billige converse, who left the crowd of people dispersed , the mayor is to see However Francis arrogance ,norway converse billig, went to the forest normalizing side , almost subordinate to the higher tone to speak ,kvinner converse storrelser, said: " Pegg son , you see,παπουτσια converse all star, this man is so arrogant ,려네

  15. BlogIcon Salg billige converse 2015.04.14 06:39  수정/삭제  댓글쓰기

    이일Do not believe that other people also think that a crazy Xiaoqing sad , she had went on to explain ,boots converse storrelser, "If you do not believe their own good view,outlet converse stovler, my brother really has been all right ! " The Kamani heard Xiaoqing said very seriously ,converse all star ελλαδα, unlike talking nonsense , then dubious check it against the body of Francis ,all star conve단다

  16. BlogIcon barn hvite converse 2015.04.14 06:39  수정/삭제  댓글쓰기

    련분Good standing here like these . "Ke Guan, you can finally woke up a small two pushed open the door and come in to see Francis is standing at the window thinking mind trance . "Well ! , I slept in this for a long time thing ? " Francis Huiguo Shen , saw the waiter a look you finally wake up , it is estimated that sleep for a very long time . "Is not a long time , it is quite a long time ! Did you k는간

  17. BlogIcon converse all star ελλαδα 2015.04.14 06:39  수정/삭제  댓글쓰기

    일고Brother not to his true body ,Oslo svarte converse, just let my brother a good experience ,norge converse veske sko, and the strength of the opponent than he fights . " , " Francis finished the outset put the snake nine - eighth style snake storm , just this strong Francis know , can not be taken lightly ,converse ψυχικο, most proud of with their own sword type to be able to try out the gap betwee메가

  18. BlogIcon Nike SKO 2015.04.14 07:19  수정/삭제  댓글쓰기

    일수Merry Christmas fitflop singaporeto learn more about all your family and yours!
    I do nothing more than wanted to understand more about be capable of geting that in the market to learn more about everyone which of you readonitsuka tiger singapores and or subscribes to learn more about my very own gleam Examiner has changed and so much in the way given that I started back whilst in the February hav부정

  19. BlogIcon fitflop shoes 2015.04.14 07:21  수정/삭제  댓글쓰기

    수련Mixed tape electronica at no time sounded and consequently white chocolate Foxes and Fiction is always that 20-year-old Torcheap fitfloponto native Warren Hildebrand,which of you made his at the outset appearance and Rochester Friday, July 9 at Boulder Coffee Co. He showed then thaonitsuka tiger minit each of them is a resource box takes to understand more about can get a layered sound that is sim종습

  20. BlogIcon Asics Baratas 2015.04.14 13:22  수정/삭제  댓글쓰기

    있마Its exciting for additional details on say a multi functional EDM Music is always finally just around the corner to New Jersey! Yes I am talking about Electric Daisy Carnival (EDC),an all in one internationally recognized EDM Music Festival dispensed everywhere in the Las Vegas every spring and summer and all the way through lots of other areas as part of your USA and World.; The in which situatio이가

  21. BlogIcon fitflop singapore 2015.04.14 13:23  수정/삭제  댓글쓰기

    을다Today’s featured artist has to be that Que,an all in one Chicago musician and dancer which of you has already been entertaining crowds considering the fact that he was 9-years age - old Que brings zapatillas New Balancea multi function certain energy for more information regarding his art as your dog painstakingly focuses beyond any and all detail regarding his art, fine-tuning almost any aspect h지리

Powerd by Tistory, designed by criuce
rss