handler

Using HandlerThread and Handler on a separate thread freezes UI thread

旧街凉风 提交于 2019-12-08 05:59:47
问题 In my project, I want to implement a timer in another thread that counts down the time spent executing a certain method in my application, and do something if it is taking too much time. When executing the MyManager.startCommand() method, the application is freezing and I don't know why since I think I am not doing anything on the UI thread. Is there anything wrong with my code? I had originally asked this question and was not experiencing an app freeze, so I don't think it's because I'm

handle SIGSEGV in Linux?

会有一股神秘感。 提交于 2019-12-08 04:24:00
问题 I need handle the SIGSEGV in my Linux app. The reason is some clean up(3-partry lib) must be done before generate core-dump. What is more, the clean up must be performed in the context of calling thread, cannot do in signal handler. So I plan in signal handler to pass the control to the calling thread, after the clean up finished, then use raise(SIGSEGV) to generate the core-dump. The real problem seems the signal_handler cannot pass the control to calling thread, no matter I use post_sem or

Steady, accurate timing in Android

不想你离开。 提交于 2019-12-08 02:29:09
问题 I'm trying to create a music sequencer app for Android devices and would appreciate some advice as to how to achieve rock-solid timing functionality. If I pass a Runnable to Handler.postDelayed and specify a delay time of x milliseconds, is that Runnable guaranteed to be executed in exactly x ms time? If I can't achieve steady and accurate timing with Handler, what other options are open to me? Thank you in advance 回答1: I don't think "hard realtime" programming is possible. The options seem

Rebus: 2 handlers in 2 processes. Hit inconsistently and alternately

蓝咒 提交于 2019-12-08 02:17:15
问题 I have two console apps using Rebus. They both reference an assembly where messages (commands and events) are defined. Console app "A" sends commands and listens to events for logging purposes (e.g.: sends a CreateTCommand and listens for TCreatedEvent). Console app "B" (which is actually an ASP.NET Core app) listens to commands and handles them (e.g.: a saga is initiated by CreateTCommand, the aggregate is created and it raises a TCreatedEvent). In another DLL inside the process of app "B"

How can I pass addition local object variable to my event handler? [duplicate]

筅森魡賤 提交于 2019-12-08 02:16:08
问题 This question already has answers here : C# passing extra parameters to an event handler? (8 answers) Closed 6 years ago . I want to a pass local object to the event handler. How can I do that? For example, how can I reference the "graphic" object, which is declared in the main function below, in the event handler function "hyperlinkButton_Click"? void main() { Graphic graphic = new Graphic(); hyperlinkButton.Click+=new RoutedEventHandler(hyperlinkButton_Click); } void hyperlinkButton_Click

聊一聊Android的消息机制

社会主义新天地 提交于 2019-12-07 21:15:33
聊一聊Android的消息机制 侯 亮 1概述 在Android平台上,主要用到两种通信机制,即Binder机制和消息机制,前者用于跨进程通信,后者用于进程内部通信。 从技术实现上来说,消息机制还是比较简单的。从大的方面讲,不光是Android平台,各种平台的消息机制的原理基本上都是相近的,其中用到的主要概念大概有: 1)消息发送者; 2)消息队列; 3)消息处理循环。 示意图如下: 图中表达的基本意思是,消息发送者通过某种方式,将消息发送到某个消息队列里,同时还有一个消息处理循环,不断从消息队列里摘取消息,并进一步解析处理。 在Android平台上,把上图的右边部分包装成了一个Looper类,这个类的内部具有对应的消息队列(MessageQueue mQueue)和loop函数。 但是Looper只是个简单的类而已,它虽然提供了循环处理方面的成员函数loop(),却不能自己凭空地运行起来,而只能寄身于某个真实的线程。而且,每个线程最多只能运作一个Looper对象,这一点应该很容易理解。 Android平台上另一个关键类是Handler。当消息循环在其寄身的线程里正式运作后,外界就是通过Handler向消息循环发出事件的。我们再画一张示意图如下: 当然,系统也允许多个Handler向同一个消息队列发送消息: 整个消息机制的轮廓也就是这些啦,下面我们来详细阐述。

How to execute business logic handler in a separate thread pool using netty

泪湿孤枕 提交于 2019-12-07 21:03:16
问题 I have a handler that needs to execute some business logic and I want that to be executed in a separate thread pool to not block the io event loop. I have added DefaultEventExecutorGroup into the pipeline as specified in http://netty.io/4.0/api/io/netty/channel/ChannelPipeline.html javadoc and http://netty.io/wiki/new-and-noteworthy-in-4.0.html#no-more-executionhandler---its-in-the-core wiki: ch.pipeline().addLast(new DefaultEventExecutorGroup(10), new ServerHandler()); Just for testing

网络编程:Reactor与Proactor的概念

十年热恋 提交于 2019-12-07 20:08:31
1、标准定义 两种I/O多路复用模式:Reactor和Proactor 一般地,I/O多路复用机制都依赖于一个事件多路分离器(Event Demultiplexer)。分离器对象可将来自事件源的I/O事件分离出来,并分发到对应的read/write事件处理器(Event Handler)。开发人员预先注册需要处理的事件及其事件处理器(或回调函数);事件分离器负责将请求事件传递给事件处理器。两个与事件分离器有关的模式是Reactor和Proactor。Reactor模式采用同步IO,而Proactor采用异步IO。 在Reactor中,事件分离器负责等待文件描述符或socket为读写操作准备就绪,然后将就绪事件传递给对应的处理器,最后由处理器负责完成实际的读写工作。 而在Proactor模式中,处理器--或者兼任处理器的事件分离器,只负责发起异步读写操作。IO操作本身由操作系统来完成。传递给操作系统的参数需要包括用户定义的数据缓冲区地址和数据大小,操作系统才能从中得到写出操作所需数据,或写入从socket读到的数据。事件分离器捕获IO操作完成事件,然后将事件传递给对应处理器。比如,在windows上,处理器发起一个异步IO操作,再由事件分离器等待IOCompletion事件。典型的异步模式实现,都建立在操作系统支持异步API的基础之上,我们将这种实现称为“系统级”异步或“真”异步

Django如何使用logging打印日志

▼魔方 西西 提交于 2019-12-07 16:26:34
Django如何使用logging打印日志 简介 Django使用python自带的logging 作为日志打印工具。简单介绍下logging。 logging 是线程安全的,其主要由4部分组成: """ 1. Logger 用户使用的直接接口,将日志传递给Handler 2. Handler 控制日志输出到哪里,console,file… 一个logger可以有多个Handler 3. Filter 控制哪些日志可以从logger流向Handler 4. Formatter 控制日志的格式 """ 使用 1.项目里sesetti.py里配置 Django通过在settings文件中使用LOGGING来定制日志输出(包括定义logger, handler, formatter等) 例如,settings文件中定义如下: BASE_LOG_DIR = os.path.join(BASE_DIR, "log") LOGGING = { 'version': 1, # 保留字 'disable_existing_loggers': False, # 禁用已经存在的logger实例 # 日志文件的格式 'formatters': { # 详细的日志格式 'standard': { 'format': '[%(asctime)s][%(threadName)s:%(thread)d]

[翻译]Android Bound Services

[亡魂溺海] 提交于 2019-12-07 16:17:59
一个bound service是一个client-server接口中的server端。一个bound service允许应用组件(比如activities)bind到它,发送请求,接收响应,甚至是执行进程间通信(IPC)。一个bound service在典型情况下,只有在它服务于另一个应用组件时才存活,而不是在后台无限期的运行。 这份文档向您说明了要如何创建bound service,包括在其他的应用组件中如何bind到service。然而,你也应该参考Services文档来 大体地 了解关于services的额外信息,比如如何在service中传送通知,设置service在前台运行,等等。 基本概念 一个bound service是一个 Service 类的实现,它允许其它应用bind到它并与它交互。为了给一个service提供binding功能,你必须实现 onBind() 回调方法。这个方法返回一个 IBinder 对象,该对象则定义了客户端可以用来与service进行交互的编程接口。 Binding到一个Started Service 如同在 Services 文档中讨论的那样,你可以创建一个service,既可以被started,也可以被bound。即,service可以通过调用 startService() 被started,从而允许service无限期的运行