WinFrom 线程的使用(开启、暂停、停止)

方法一:


启用线程:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;


namespace WindowsFormsApplication1
{
    public delegate void BackGroundWorkers();


    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
            
        }
Thread th;

        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            GetICount();   
        }


        int i = 0;


        public void GetICount()
        {
            i++;
            this.label1.Text = i.ToString();
            Thread.Sleep(1000);  //暂停线程
             = new Thread(new ThreadStart(GetICount));
            th.IsBackground = true;
            th.Start();
        }
    }
}


停止线程:

public void StopThread()

{

th.Abort();   //停止线程

}


方法二:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;


namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
        }


        private delegate void GetInfo();




        private void Form2_Load(object sender, EventArgs e)
        {
            GetTime();
        }
        
        private int i = 0;


        /// <summary>
        /// 线程执行的方法
        /// </summary>
        public void GetTime()
        {


            i++;
            this.label1.Text = i.ToString();
            Thread.Sleep(200);
            GetInfo gets = new GetInfo(GetTime);
            gets.BeginInvoke(null, null);
        }
    }
}



Start():启动线程;
Sleep(int):静态方法,暂停当前线程指定的毫秒数; 
Abort():通常使用该方法来终止一个线程;
Suspend():该方法并不终止未完成的线程,它仅仅挂起线程,以后还可恢复; 
Resume():恢复被Suspend()方法挂起的线程的执行。

### HBase 的存储过程和工作机制 #### 一、HBase 存储过程详解 HBase 基于 LSM (Log-Structured Merge) 树模型实现其高效的写入性能。以下是数据在 HBase 中的存储流程: 1. **客户端请求处理** 当客户端发起写入请求时,数据会被记录到 WAL(Write-Ahead Log),即 HLog 文件中[^1]。这一操作确保即使发生系统崩溃,未持久化的数据也可以通过重放日志的方式恢复。 2. **内存缓冲区 MemStore** 随后,数据被加载至内存中的 MemStore 缓冲区。在此阶段,数据以有序的形式保存以便后续快速写入磁盘[^2]。 3. **刷写到磁盘** 当 MemStore 达到预设阈值时,其中的数据将被刷新并写入磁盘上的 HFile 文件。此过程中,数据按照列族进行物理分区存储,从而优化查询效率[^3]。 4. **压缩与合并** 定期执行 Minor Compaction 和 Major Compaction 来减少过多的小型 HFiles 数量以及清理过期或删除标记的数据项。Major Compaction 默认每七天运行一次[^5]。 #### 二、RegionServer 工作原理 RegionServer 是 HBase 分布式架构的核心组件之一,负责管理分配给它的 Regions 并响应来自用户的读/写请求。 1. **Region 管理** 每个 RegionServer 维护若干个 Regions,而这些 Regions 构成了表的实际存储单位。不同地区的 Regions 能够分布于集群内的各个节点上以达到负载均衡的目的;然而单个 Region 不允许跨多台服务器分割存放。 2. **WAL 日志维护** 所有针对该 RegionServer 下属 Regions 进行的操作均需先行登记至统一的日志文件——HLog 中。正常情况下很少直接访问 HLogs,但在意外停机或者灾难恢复场景下则显得尤为重要。 3. **缓存策略 BlockCache** 为了加速频繁访问的数据检索速度,HBase 实现了一套复杂的缓存体系结构称为 BlockCache。它进一步细分为 three-tiered cache hierarchy 包括 single-access, multi-access 和 in-memory regions,各占据总容量比例分别为 25%, 50% 及剩余部分用于特定需求如全内存模式下的大对象支持等[^4]。 ```python # 示例代码展示如何设置 major compaction 时间间隔配置参数 from hbase import Configuration config = Configuration() config.set('hbase.hregion.majorcompaction', '604800000') # 设置为7天毫秒数 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值