cancel executing too slowquery 可以吗

您所在的位置: &
关于AsyncTask中的cancel方法
关于AsyncTask中的cancel方法
eoe Android开发者社区
在adroid 应用程序中,我们经常会用到异步加载。 所以我们也要知道如何取消加载。 比如,当用户点击图片加载时,如果用户可能需要取消加载。 怎样取消呢 我去百度找了很久也没找到 。于是就自己去API文档中查找。
在这里总结一下:
Cancelling
A task can be cancelled at any time by invoking cancel(boolean).
Invoking this method will cause subsequent calls to isCancelled() to return
true. After invoking this method, onCancelled(Object), instead of
onPostExecute(Object) will be invoked after doInBackground(Object[]) returns. To
ensure that a task is cancelled as quickly as possible, you should always check
the return value of isCancelled() periodically from doInBackground(Object[]), if
possible (inside a loop for instance.)
这是话意思是
我们可以随时调用 cancel(boolean)去取消这个加载任务,调用这个方法会间接调用 iscancelled 并且返回true
当调用cancel()后,在doInBackground()return后 我们将会调用onCancelled(Object)
不在调用onPostExecute(Object)
为了保证任务更快取消掉,你应该在doInBackground()周期性的检查iscancelled
去进行判断。
**注意,我们的oncancel和onPostExecute一样,都是在UI线程中执行。。。所以当我们想要取消之后,有些界面变化
我们可以在oncancel里面改变UI.
关于cancel方法
public final boolean cancel (boolean
mayInterruptIfRunning)
Attempts to cancel execution of this task. This
attempt will fail if the task has already completed, already been cancelled, or
could not be cancelled for some other reason. If successful, and this task has
not started when cancel is called, this task should never run. If the task has
already started, then the mayInterruptIfRunning parameter determines whether the
thread executing this task should be interrupted in an attempt to stop the
某些情况下,我们调用cancel(true)可能就会失效
比如 :task已经加载完成,或者
已经取消过一次,或者是其他情况【编辑推荐】【责任编辑: TEL:(010)】
关于&&&&的更多文章
本书是一本系统讲解Android应用开发安全的书籍。它首先介绍了And
随着秋的到来,各路才子佳人渐渐开始回到学校上课。不
百度推出轻应用引起业界火热议论,收购91和推出轻应用
App搜索对应用的影响不容忽视,目前应用商店仍采用最
本书是针对全国计算机技术与软件专业技术资格(水平)考试而编写的,书中详尽分析与解答了2006年上半年的程序员级、软件设计师级
Windows Phone专家
Android开发专家
51CTO旗下网站博客访问: 607242
博文数量: 119
注册时间:
ITPUB论坛APP
ITPUB论坛APP
APP发帖 享双倍积分
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: Linux
How to CANCEL a query running in another session?Here’s a treat for Oracle geeks, hackers and maniacs out there…Update: As the beginning says, this article was meant as something interesting about Oracle’s internals and CTRL+C / OCICancel() handling. There’s a more practical way for canceling session calls if you are running Oracle Enterprise Edition and are currently using resource manager:You can set the consumer group for a session to CANCEL_SQL to cancel its current call:DBMS_RESOURCE_MANAGER.SWITCH_CONSUMER_GROUP_FOR_SESS (session_id IN NUMBER,session_serial IN NUMBER,consumer_group&IN VARCHAR2);Thanks to commenter “null” for this info. Note that I haven’t tested how/whether this feature works correctly so there’-)I recently received a question about how to&cancel&queries running in another Oracle session, so that the session would not be killed, but would remain alive.Well, there’s no supported way I can tell you, but thanks to how Oracle handles out-of-band breaks on Unix platforms, you can cancel database calls using an OS tool – kill.Before we go on, here’s how query cancellation (pressing CTRL+C in sqlplus for example) works in Oracle:The user presses CTRL+C or clicks some button in App which runs OCICancel()The client process sends an&urgent&TCP packet (which is a regular TCP packet with URG bit set) to the socket in the database server it is connected toThe server OS TCP stack receives the urgent TCP packet and sends URGENT signal to the process which owns the socket (the Oracle server process)Unix interrupts whatever the current process was doing and calls the URGENT signal handler function (which Oracle has registered during process startup)The urgent signal handler blindly assumes that the urgent signal has been received because user wants to cancel the query, stops the execution and returns back with an error: ORA-01013: user requested cancel of current operationSo, if we can’t make our application send the break packet, OCICancel() then we can just send the SIGURG signal to the Oracle process just like the OS TCP stack would do when it receives the packet with urgent bit set.Here’s an example:In one session I’m running a DBMS_STATS call:SQL> exec dbms_stats.gather_database_I identify the SPID of that session’s process and send an URG signal to that process:kill -URG 4476And the call gets cancelled in the other session:SQL> exec dbms_stats.gather_database_BEGIN dbms_stats.gather_database_ END;&*ERROR at line 1:ORA-00604: error occurred at recursive SQL level 1ORA-01013: user requested cancel of current operationORA-06512: at "SYS.DBMS_STATS", line 13336ORA-06512: at "SYS.DBMS_STATS", line 13682ORA-06512: at "SYS.DBMS_STATS", line 13826ORA-06512: at "SYS.DBMS_STATS", line 13790ORA-06512: at line 1My session was not killed – I still can run queries in it:SQL> select *&D-X&SQL>This works only on Unix platforms. Also this does&not&work when your client application is Windows sqlplus! This is because Windows sqlplus does not set up the out-of-band break checking properly when connecting. Maybe this is because old Windows versions TCP stacks didn’t know anything about urgent TCP packets! :)A word of warning – this stuff is not for your everyday production usage! While it works and we know&how and why&it works, it’s not a good idea to send “random” signals to Oracle processes at your will. So the better way is to make your application able to cancel its database calls when you want it, but well in real world its not always (or should I even say rarely) possible.Another thing to consider is when you run Oracle with Direct NFS, there will be network connections to the NFS server used by your server process, in addition to the client-server communication. I haven’t tested what happens when you send URG packet to a process in the DNFS case.So try this o-)If you want to know more about query cancelling and what the in-band and out-of-band break checking is then you can read one of my old blog posts about it:Related Posts&附:网上发现的其他方法:
DECLARE& l_status v$session.status%TYPE;BEGIN& dbms_system.set_ev(&sid, &serial, 10237, 1, '');& LOOP&&& SELECT status&&&&& INTO l_status&&&&& FROM v$session&&&& WHERE sid = &sid&&&&&& and serial# = &&&& EXIT WHEN l_status = 'INACTIVE';& END LOOP;& dbms_system.set_ev(&sid, &serial, 10237, 0, '');END;
阅读(1388) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。posts - 278,&
comments - 116,&
trackbacks - 0
jQuery Alert Dialogs,又一个基于jQuery的提示框插件,主要包括Alert、Confirm、prompt这三种,还有一个高级范例,可以在提示框内嵌入HTML语言,可以自定义风格样式。jQuery的提示框插件有很多种,每一款都是出自不同的高人之手,因此都比较有自己的特点,包括风格和使用方法等。效果体验:英文版:这个Jquery插件的目的是替代JavaScript的标准函数aert(),confirm(),和 prompt()。这个插件有如下这些特点:1:这个插件可以使你可以支持你自己的css制定。使你的网站看起来更专业。2:允许你自定义对话框的标题。3:在IE7中,可以使你避免使用JavaScript 的prompt()函数带来的页面重新加载。4:这些方法都模拟了Windows的模式对话框。在你改变改变浏览器窗口大小时候,它能够自适应用户窗口的调整。5:如果你引入了jQuery UI Draggable plugin插件,那这个插件也可以被自由拖动。jquery.alerts.js代码:
// Download by
// 由 柯乐义 改进改插件,使插件适用于新版的jquery(比如1.10.1) 版本
// Visit /a/bjac/no0m3cb1.htm for more information
jAlert( message, [title, callback] )
jConfirm( message, [title, callback] )
jPrompt( message, [value, title, callback] )
// History:
1.00 - Released (29 December 2008)
(function($) {
$.alerts = {
// These properties can be read/written by accessing $.alerts.propertyName from your scripts at any time
verticalOffset: -75, // vertical offset of the dialog from center screen, in pixels
horizontalOffset: 0, // horizontal offset of the dialog from center screen, in pixels/
repositionOnResize: true, // re-centers the dialog on window resize
overlayOpacity: .01, // transparency level of overlay
overlayColor: '#FFF', // base color of overlay
draggable: true, // make the dialogs draggable (requires UI Draggables plugin)
okButton: '&OK&', // text for the OK button
cancelButton: '&Cancel&', // text for the Cancel button
dialogClass: null, // if specified, this class will be applied to all dialogs
// Public methods
alert: function(message, title, callback) {
if( title == null ) title = 'Alert';
$.alerts._show(title, message, null, 'alert', function(result) {
if( callback ) callback(result);
confirm: function(message, title, callback) {
if( title == null ) title = 'Confirm';
$.alerts._show(title, message, null, 'confirm', function(result) {
if( callback ) callback(result);
prompt: function(message, value, title, callback) {
if( title == null ) title = 'Prompt';
$.alerts._show(title, message, value, 'prompt', function(result) {
if( callback ) callback(result);
// Private methods
_show: function(title, msg, value, type, callback) {
$.alerts._hide();
$.alerts._overlay('show');
$("BODY").append(
'&div id="popup_container"&' +
'&h1 id="popup_title"&&/h1&' +
'&div id="popup_content"&' +
'&div id="popup_message"&&/div&' +
'&/div&' +
'&/div&');
if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
// IE6 Fixvar pos = ('undefined' == typeof (document.body.style.maxHeight)) ? 'absolute' : 'fixed';
$("#popup_container").css({
position: pos,
zIndex: 99999,
padding: 0,
$("#popup_title").text(title);
$("#popup_content").addClass(type);
$("#popup_message").text(msg);
$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '&br /&') );
$("#popup_container").css({
minWidth: $("#popup_container").outerWidth(),
maxWidth: $("#popup_container").outerWidth()
$.alerts._reposition();
$.alerts._maintainPosition(true);
switch( type ) {
case 'alert':
$("#popup_message").after('&div id="popup_panel"&&input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /&&/div&');
$("#popup_ok").click( function() {
$.alerts._hide();
callback(true);
$("#popup_ok").focus().keypress( function(e) {
if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
case 'confirm':
$("#popup_message").after('&div id="popup_panel"&&input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /& &input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /&&/div&');
$("#popup_ok").click( function() {
$.alerts._hide();
if( callback ) callback(true);
$("#popup_cancel").click( function() {
$.alerts._hide();
if( callback ) callback(false);
$("#popup_ok").focus();
$("#popup_ok, #popup_cancel").keypress( function(e) {
if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
case 'prompt':
$("#popup_message").append('&br /&&input type="text" size="30" id="popup_prompt" /&').after('&div id="popup_panel"&&input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /& &input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /&&/div&');
$("#popup_prompt").width( $("#popup_message").width() );
$("#popup_ok").click( function() {
var val = $("#popup_prompt").val();
$.alerts._hide();
if( callback ) callback( val );
$("#popup_cancel").click( function() {
$.alerts._hide();
if( callback ) callback( null );
$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
if( value ) $("#popup_prompt").val(value);
$("#popup_prompt").focus().select();
// Make draggable
if( $.alerts.draggable ) {
$("#popup_container").draggable({ handle: $("#popup_title") });
$("#popup_title").css({ cursor: 'move' });
} catch(e) { /* requires jQuery UI draggables */ }
_hide: function() {
$("#popup_container").remove();
$.alerts._overlay('hide');
$.alerts._maintainPosition(false);
_overlay: function(status) {
switch( status ) {
case 'show':
$.alerts._overlay('hide');
$("BODY").append('&div id="popup_overlay"&&/div&');
$("#popup_overlay").css({
position: 'absolute',
zIndex: 99998,
top: '0px',
left: '0px',
width: '100%',
height: $(document).height(),
background: $.alerts.overlayColor,
opacity: $.alerts.overlayOpacity
case 'hide':
$("#popup_overlay").remove();
_reposition: function() {
var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalO
var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalO
if( top & 0 ) top = 0;
if( left & 0 ) left = 0;
// IE6 fix
if ('undefined' == typeof (document.body.style.maxHeight)) top = top + $(window).scrollTop();
$("#popup_container").css({
top: top + 'px',
left: left + 'px'
$("#popup_overlay").height( $(document).height() );
_maintainPosition: function(status) {
if( $.alerts.repositionOnResize ) {
switch(status) {
case true:
$(window).bind('resize', function() {
$.alerts._reposition();
case false:
$(window).unbind('resize');
// Shortuct functions
jAlert = function(message, title, callback) {
$.alerts.alert(message, title, callback);
jConfirm = function(message, title, callback) {
$.alerts.confirm(message, title, callback);
jPrompt = function(message, value, title, callback) {
$.alerts.prompt(message, value, title, callback);
})(jQuery);
#popup_container {
font-family: Arial, sans-serif;
font-size: 12px;
min-width: 300px; /* Dialog will be no smaller than this */
max-width: 600px; /* Dialog will wrap after this width */
background: #FFF;
border: solid 5px #999;
color: #000;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
#popup_title {
font-size: 14px;
font-weight: bold;
text-align: center;
line-height: 1.75em;
color: #666;
background: #CCC url(images/title.gif) top repeat-x;
border: solid 1px #FFF;
border-bottom: solid 1px #999;
cursor: default;
padding: 0em;
margin: 0em;
#popup_content {
background: 16px 16px no-repeat url(/keleyi/phtml/jqplug/index/info.gif);
padding: 1em 1.75em;
margin: 0em;
#popup_content.alert {
background-image: url(/keleyi/phtml/jqplug/index/info.gif);
#popup_content.confirm {
background-image: url(/keleyi/phtml/jqplug/index/important.gif);
#popup_content.prompt {
background-image: url(/keleyi/phtml/jqplug/index/help.gif);
#popup_message {
padding-left: 48px;
#popup_panel {
text-align: center;
margin: 1em 0em 0em 1em;
#popup_prompt {
margin: .5em 0em;
还需引用:&script type="text/javascript" src="/keleyi/pmedia/jquery-1.9.1.min.js"&&/script&&script src="/keleyi/pmedia/jquery/ui/1.10.3/js/jquery-ui-1.10.3.min.js" type="text/javascript"&&/script&
更多信息请访问:
阅读(...) 评论()jquery easyui DataGrid 实例,增、删、查、改基础功能 -
- ITeye技术网站
&%@ page language="java" contentType="text/ charset=UTF-8" pageEncoding="UTF-8"%&
&%@ include file="/common/taglibs.jsp"%&
&!DOCTYPE html&
&title&价格案例管理&/title&
&table id="condoPriceGrid" class="easyui-datagrid"&&/table&
&form id="condoPriceForm" method="post" class="form"&
&input type="hidden" id="id" name="id" value="${condoPrice.id}"&
&input type="hidden" id="condoId" name="condoId" value="${condoPrice.condoId}"&
&table class="input"&
&th style="width: 85"&小区名称:&/th&
&td&&input id="name" name="name" type="text" value="${condoPrice.name}"
class="easyui-validatebox" data-options="required:true"/&&/td&
&th style="width: 85"&成交时间:&/th&
&td&&input id="bargainDay" name="bargainDay" type="text" value="${condoPrice.bargainDay}" class="easyui-datebox" data-options="formatter:dateBoxFormatter,parser:dateBoxParser" /&&/td&
&th style="width: 85"&面积:&/th&
&td&&input id="bargainArea" name="bargainArea" type="text" value="${condoPrice.bargainArea}"
class="easyui-validatebox"/& ㎡&/td&
&th style="width: 85"&成交价格:&/th&
&td&&input id="bargainPrice" name="bargainPrice" type="text" value="${condoPrice.bargainPrice}"
class="easyui-validatebox" /& 万元&/td&
&div id="add" class="easyui-window" title="新增" closed="true" style="width: 500height:300" iconCls="icon-add" closed="true" maximizable="false" minimizable="false" collapsible="false"&
&div id="addConPrice"&&/div&
&div style="text-align:"&
&a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveCondoPrice('#add');"&保存&/a&
&a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="closeWin('#add')"&取消&/a&
&div id="edit" class="easyui-window" title="修改" closed="true" style="width: 500height:300 overflow:" maximizable="false" minimizable="false" collapsible="false"&
&div id="editConPrice"&&/div&
&div style="text-align:"&
&a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveCondoPrice('#edit');"&修改&/a&
&a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="closeWin('#edit')"&取消&/a&
&div id="query" class="easyui-window" title="查询" closed="true" style="width: 400height:120 overflow:" maximizable="false" minimizable="false" collapsible="false"&
&form id="queryForm" method="post" class="form"&
&th style="width: 85 text-align:"&小区名称:&/th&
&td&&input id="condoName" name="condoName" type="text" class="easyui-validatebox" data-options="required:true" /&&/td&
&td&&a class="easyui-linkbutton" iconCls="icon-search" href="javascript:void(0);" onclick="query()"&查询&/a&&/td&
&script type="text/javascript"&
$(function(){
var queryParams = {};
$('#condoPriceForm').hide();
$("#condoPriceGrid").datagrid({
fit: true,
nowrap:false,
border: false,
striped: true,
collapsible:true,
url: '${ctx}/condoprice/load',
queryParams:{},
loadMsg:'数据加载中......',
frozenColumns:[[
{field:'ck',checkbox:true}
columns:[[
{field:'name',title:'小区名称',width:200},
{field:'bargainDay',title:'成交时间',width:200},
{field:'bargainArea',title:'面积',width:200},
{field:'bargainPrice',title:'成交价格',width:200},
{field:'condoId', hidden: true},
{field:'id', hidden: true}
pagination:true,
rownumbers:true,
singleSelect:true,
toolbar: [{
text: '搜索',
iconCls: 'icon-search',
handler: function(){
$("#query").window('open');
$("#queryForm").form('clear');
text: '新增',
iconCls: 'icon-add',
handler: function(){
$('#add').window('open');
$('#condoPriceForm').show();
$('#condoPriceForm').form('clear');
$('#condoPriceForm').appendTo('#addConPrice');
$('#name').attr("disabled", false);
text: '编辑',
iconCls: 'icon-edit',
handler: handleEdit
text: '删除',
iconCls: 'icon-remove',
handler: handleRemove
onBeforeLoad: function(){
if(queryParams){
$('#condoPriceGrid').datagrid('options').queryParams = {};
function handleEdit(){
var select = $("#condoPriceGrid").datagrid('getSelected');
if(select){
$('#edit').window('open');
$('#condoPriceForm').show();
$('#condoPriceForm').appendTo('#editConPrice');
$('#name').val(select.name);
$('#bargainDay').datebox('setValue', select.bargainDay);
$('#bargainPrice').val(select.bargainPrice);
$('#bargainArea').val(select.bargainArea);
$('#id').val(select.id);
$('#condoId').val(select.condoId);
$('#name').attr("readonly", true);
$('#name').css("color", "red");
$.messager.alert('warning','请选择一行数据','warning');
function saveCondoPrice(el) {
$("#condoPriceForm").form('submit', {
url: '${ctx}/condoprice/save',
success:function(data){
var json = $.parseJSON(data);
if(json.success){
closeWin(el);
//刷新数据
$("#condoPriceGrid").datagrid('reload');
parent.$.messager.alert('温馨提示', json.message, 'info');
function query(){
var name = $('#condoName').val();
if(name != ""){
queryParams = $('#condoPriceGrid').datagrid('options').queryP
queryParams.condoName =
//刷新数据
$("#condoPriceGrid").datagrid('reload');
closeWin('#query');
$.messager.alert('warning','请输入小区名称!','warning');
$("input[name=condoName]").focus();
function handleRemove(){
var select = $("#condoPriceGrid").datagrid('getSelected');
if(select){
$.messager.confirm('confirm','确认删除么?',function(id){
type: 'POST',
url: '${ctx}/condoprice/remove',
data: {"id": select.id},
dataType: 'json',
success: function(data){
if(data.success){
//刷新数据
$("#condoPriceGrid").datagrid('reload');
parent.$.messager.alert('温馨提示', data.message, 'info');
$('#tt').datagrid('reload');
$.messager.alert('warning','请选择一行数据','warning');
//关闭弹出窗口
function closeWin(el){
$(el).window('close');
lijuanlovey
浏览: 8532 次
来自: 深圳

我要回帖

更多关于 executing cl.exe. 的文章

 

随机推荐