Fucked Java.

本文探讨了在使用JTable进行数据刷新时,通过创建线程避免出现ArrayIndexOutOfBoundsException异常的方法。介绍了如何利用SwingUtilities.invokeLater()来确保线程安全地更新JTable数据,同时提供了解决方案的实现细节。

使用JTable,并对数据进行频繁刷新(清除+添加),结果频繁出现如下异常:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 7 >= 6

经网上搜索,发现了一个解决方案,但是对问题根源没有深究。

在对JTable数据刷新是采用如下方法可避免以上异常:

private void UpdateWithThread()
    {
        Thread thread = new Thread()
        {
            @Override
            public void run()
            {
                Runnable runnable = new Runnable()
                {
                    @Override
                    public void run()
                    {
                        try
                        {

                               clearData();// 删除JTable中的数据

                               AddData();//对JTable添加新数据
                        }
                        catch (Exception e)
                        {
                            e.printStackTrace();
                        }
                    }
                };
                SwingUtilities.invokeLater(runnable);
            }
        };
        thread.start();
    }

对于以上解决方案的论证有待研究,但确实可以避免出现上面的异常。

内容概要:本文详细介绍了“秒杀商城”微服务架构的设计与实战全过程,涵盖系统从需求分析、服务拆分、技术选型到核心功能开发、分布式事务处理、容器化部署及监控链路追踪的完整流程。重点解决了高并发场景下的超卖问题,采用Redis预减库存、消息队列削峰、数据库乐观锁等手段保障数据一致性,并通过Nacos实现服务注册发现与配置管理,利用Seata处理跨服务分布式事务,结合RabbitMQ实现异步下单,提升系统吞吐能力。同时,项目支持Docker Compose快速部署和Kubernetes生产级编排,集成Sleuth+Zipkin链路追踪与Prometheus+Grafana监控体系,构建可观测性强的微服务系统。; 适合人群:具备Java基础和Spring Boot开发经验,熟悉微服务基本概念的中高级研发人员,尤其是希望深入理解高并发系统设计、分布式事务、服务治理等核心技术的开发者;适合工作2-5年、有志于转型微服务或提升架构能力的工程师; 使用场景及目标:①学习如何基于Spring Cloud Alibaba构建完整的微服务项目;②掌握秒杀场景下高并发、超卖控制、异步化、削峰填谷等关键技术方案;③实践分布式事务(Seata)、服务熔断降级、链路追踪、统一配置中心等企业级中间件的应用;④完成从本地开发到容器化部署的全流程落地; 阅读建议:建议按照文档提供的七个阶段循序渐进地动手实践,重点关注秒杀流程设计、服务间通信机制、分布式事务实现和系统性能优化部分,结合代码调试与监控工具深入理解各组件协作原理,真正掌握高并发微服务系统的构建能力。
import os from tkinter import * from tkinter.messagebox import * import psutil root = Tk() root.geometry('280x320') root.title('再见极域') root.wm_attributes('-topmost', 1) root.resizable(False, False) root.configure(bg = '#1E1E1E') font1 = ('微软雅黑', 9) font2 = ('Courier New', 16, 'bold') font3 = ('微软雅黑', 10) ICED = False TOP = True CON = True Label(root, text = '极域状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 0, y = 10, width = 140, height = 20) Label(root, text = '广播状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 140, y = 10, width = 140, height = 20) Label(root, text = '键盘状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 0, y = 70, width = 140, height = 20) Label(root, text = '置顶状态', bg = '#1E1E1E', fg = '#A0A0A0', font = font1).place(x = 140, y = 70, width = 140, height = 20) la = Label(root, bg = '#1E1E1E', font = ('Courier New', 13, 'bold')) lb = Label(root, bg = '#1E1E1E', font = font2) lc = Label(root, text = 'OPENED', fg = 'lime', bg = '#1E1E1E', font = font2) ld = Label(root, text = 'ON', fg = 'lime', bg = '#1E1E1E', font = font2) la.place(x = 0, y = 30, width = 140, height = 45) lb.place(x = 140, y = 30, width = 140, height = 45) lc.place(x = 0, y = 90, width = 140, height = 45) ld.place(x = 140, y = 90, width = 140, height = 45) def cba1(): ba.config(fg = '#660000', bg = 'red', activeforeground = 'red', activebackground = '#660000', text = '上键盘锁', command = cba2) lc.config(text = 'OPENED', fg = 'lime') #--------------------------- #----------开键盘锁---------- #--------------------------- def cba2(): ba.config(fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', text = '开键盘锁', command = cba1) lc.config(text = 'LOCKED', fg = 'red') #--------------------------- #----------上键盘锁---------- #--------------------------- ba = Button(root, text = '上键盘锁', borderwidth = 0, bg = 'red', font = font3, activeforeground = 'red', activebackground = '#660000', relief = GROOVE, fg = '#660000', command = cba2) ba.place(x = 10, y = 140, width = 125, height = 45) def cbb1(): bb.config(fg = '#660000', bg = 'red', activeforeground = 'red', activebackground = '#660000', text = '取消置顶', command = cbb2) ld.config(text = 'ON', fg = 'lime') TOP = 1 root.wm_attributes('-topmost', 1) def cbb2(): bb.config(fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', text = '置顶窗口', command = cbb1) ld.config(text = 'ON', fg = 'red') TOP = 0 root.wm_attributes('-topmost', 0) bb = Button(root, text = '取消置顶', borderwidth = 0, bg = 'red', font = font3, activeforeground = 'red', activebackground = '#660000', relief = GROOVE, fg = '#660000', command = cbb2) bb.place(x = 145, y = 140, width = 125, height = 45) # 这三个功能暂时没弄 def cbc(): bc['state'] = 'disabled' bd['state'] = 'normal' be['state'] = 'normal' #--------------------------- #-----------窗口化---------- #--------------------------- def cbd(): bc['state'] = 'normal' bd['state'] = 'disabled' be['state'] = 'normal' #--------------------------- #-----------最小化---------- #--------------------------- def cbe(): bc['state'] = 'normal' bd['state'] = 'normal' be['state'] = 'disabled' #--------------------------- #----------复原窗口---------- #--------------------------- bc = Button(root, text = '窗口化', borderwidth = 0, font = font3, bg = '#00A7FF', activeforeground = '#00A7FF', activebackground = '#0000BF', relief = GROOVE, fg = '#0000BF', command = cbc) bc.place(x = 10, y = 195, width = 76, height = 45) bd = Button(root, text = '最小化', borderwidth = 0, font = font3, bg = '#00A7FF', activeforeground = '#00A7FF', activebackground = '#0000BF', relief = GROOVE, fg = '#0000BF', command = cbd) bd.place(x = 96, y = 195, width = 76, height = 45) be = Button(root, text = '复原窗口', borderwidth = 0, font = font3, bg = '#00A7FF', activeforeground = '#00A7FF', activebackground = '#0000BF', relief = GROOVE, fg = '#0000BF', command = cbe) be['state'] = 'disabled' be.place(x = 182, y = 195, width = 88, height = 45) def cbf(): os.system('taskkill /im StudentMain.exe /f') showinfo('成功', '操作成功执行!') # ntsd 需要事先放到下面这个路径 def cbg(): os.system('C:\\Windows\\Temp\\ntsd.exe -c q -pn StudentMain.exe') showinfo('成功', '操作成功执行!') def cbh1(): global ICED s = [] for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs = ['pid', 'name']) except psutil.NoSuchProcess: pass else: s.append(pinfo) for i in s: if i['name'] == 'StudentMain.exe': p = i['pid'] break pro = psutil.Process(p) pro.suspend() ICED = True bh.config(fg = '#660000', bg = 'red', text = '解冻极域', activeforeground = 'red', activebackground = '#660000', command = cbh2) def cbh2(): global ICED s = [] for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs = ['pid', 'name']) except psutil.NoSuchProcess: pass else: s.append(pinfo) for i in s: if i['name'] == 'StudentMain.exe': p = i['pid'] break pro = psutil.Process(p) pro.resume() ICED = False bh.config(fg = '#006600', bg = 'lime', text = '冻结极域', activeforeground = 'lime', activebackground = '#006600', command = cbh1) bf = Button(root, text = 'TASKKILL', borderwidth = 0, fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', relief = GROOVE, command = cbf) bf.place(x = 10, y = 255, width = 80, height = 45) bg = Button(root, text = 'NTSD', borderwidth = 0, fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', relief = GROOVE, command = cbg) bg.place(x = 100, y = 255, width = 80, height = 45) bh = Button(root, text = '冻结极域', borderwidth = 0, fg = '#006600', bg = 'lime', activeforeground = 'lime', activebackground = '#006600', relief = GROOVE, command = cbh1) bh.place(x = 190, y = 255, width = 80, height = 45) FUCKED = False def fla(): global ICED, FUCKED, CON s = [] k = [] for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs = ['pid', 'name']) except psutil.NoSuchProcess: pass else: s.append(pinfo['name']) k.append(pinfo) if 'StudentMain.exe' in s: if CON: la.config(font = ('Courier New', 13, 'bold')) CON = False for i in k: if i['name'] == 'StudentMain.exe': we = i['pid'] break if ICED: la.config(text = 'ICED', fg = 'yellow') lb.config(text = 'ICED', fg = 'yellow') else: la.config(text = f'ON\npid={we}', fg = 'red') lb.config(text = 'UNKNOWN', fg = 'yellow') if FUCKED: bc['state'] = 'normal' bd['state'] = 'normal' be['state'] = 'disabled' bf['state'] = 'normal' bg['state'] = 'normal' bh['state'] = 'normal' FUCKED = False else: CON = True la.config(text = 'OFF', fg = 'lime') lb.config(text = 'OFF', fg = 'lime') bc['state'] = 'disabled' bd['state'] = 'disabled' be['state'] = 'disabled' bf['state'] = 'disabled' bg['state'] = 'disabled' bh['state'] = 'disabled' la.config(font = font2) FUCKED = True if TOP: root.attributes('-topmost', 1) root.after(700, fla) root.after(500, fla) root.mainloop()
09-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值