const{createApp}=Vue const{createVuetify,useGoTo,useDisplay}=Vuetify var data={alert:{show:false,color:'success',text:'',timeout:0,},theme:{dark:false,},nav:{showDrawer:false,showTOC:true,tocPanel:0,tab:'account',post:{discussionId:5581,currentPage:1,targetPage:1,total:41,anchor:0,goToOptions:{container:null,duration:0,easing:'easeInOutCubic',offset:-100,},worker:null,task:[],active:[],apiLock:[],originLike:new Map([]),},related:{block:1,}},search:{width:80,text:null,loading:false,},tags:[{id:28,url:'/t/3d104b0f6a045c7568772c310313',name:'Java',color:'#FFA726',icon:'mdi-language-java',},],posts:[{id:64500,num:0,uid:642,content:'\u003Cp\u003E最近项目想上直播和拍卖业务,自身流量也是比较大,想问下目前业界 ws 方案下是不是更推荐 netty 或者有没有其他可以参考的方案呢?\u003C/p\u003E\u003Cp\u003E直播推流这快准备用阿里云的,直播上会用到 ws 的也就是评论,拍卖可能就是出价和评论\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 09:24:46',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64501,num:1,uid:58,content:'不要直接用 netty ,用 vertx 或者 quarkus',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 09:29:21',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64502,num:2,uid:874,content:'我们公司是做会议的,直播推流用阿里云再找个云服务商做备份,单一服务商遇到问题的时候哭都来不及。\u003Cbr\u003E\u003Cbr\u003Ews 是用的 netty',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 09:31:59',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64503,num:3,uid:5791,content:'用 J**a 21 虚拟线程同步处理一把梭,别想着那些啥响应式啥的异步啥的提高性能了。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 09:47:25',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64504,num:4,uid:3082,content:'vertx 更好用',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 09:47:35',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64505,num:5,uid:3778,content:'vertx 底层就是 netty',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 09:51:04',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64506,num:6,uid:629,content:'虚拟线程吧,响应式编程复杂度太高了,甚至比切换 kotlin 的成本都高',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:14:02',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64507,num:7,uid:11395,content:'老老实实用 netty\u003Cbr\u003E大流量+响应式编程到时都不知道死哪里...',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:16:43',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64508,num:8,uid:279,content:'虚拟线程不推荐使用.\u003Cbr\u003E1: 虚拟线程的出现是减少 IO 的产生, 如果是非 IO 操作使用虚拟线程只会增加应用负担.\u003Cbr\u003E2: 虚拟线程是通过用户态上进行上下文切换减少内核态切换. 虚拟线程使用 Continuation 实现的, 这个是个对象, 也就是会占用内存. 当你操作越多, 内存占用也会疯涨. 原有平台线程 (Thread) 则是由物理资源 (系统资源) 限制, 而虚拟线程则没有这层限制, 操作不好容易导致 OOM.',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:18:31',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64509,num:9,uid:279,content:'就目前的 JDK-21-LTS 的虚拟线程还存在致命问题:\u003Cbr\u003E\u003Cbr\u003E- 在使用 synchronized 场景下会将虚拟线程 PIN 到平台线程 (锁在了某一个线程上)\u003Cbr\u003E这是由于当前对 synchronized 的实现需要直到锁当前持有的线程对象. 而虚拟线程是上层包装出来的, 所以必须强绑到某一个平台线程 (Thread) 上才能实现. 如果在 IO 操作下会基本和平台线程无异.\u003Cbr\u003E\u003Cbr\u003E- 在 Medium 中, Netflix 团队遇到使用虚拟线程死锁的情况.\u003Cbr\u003E这个问题和 synchronized 关联. 具体可以参考 [Medium Netflix Tech]( https://netflixtechblog.com/j**a-21-virtual-threads-dude-wheres-my-lock-3052540e231d)',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:27:10',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[17,23,],mentionUsers:[],likeUsers:[],},{id:64510,num:10,uid:642,content:'收到',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:28:18',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64511,num:11,uid:642,content:'收到',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:28:24',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64512,num:12,uid:642,content:'收到',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:28:29',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64513,num:13,uid:642,content:'还是哥专业啊~ 理论上我们新项目不会上新的 jdk 版本,还是继续用 J**a8',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:29:27',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64514,num:14,uid:642,content:'有的时候我觉得 J**a 对于中小企业真是一种负担,明明可以用 Go 来做业务开发,能减少不少服务器成本!',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:32:12',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64515,num:15,uid:1330,content:'别搞 j**a8 了,起码 17 起步,现在各个生态配台早都跟上了。netty 是稳健的选择多少年市场验证过了',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:57:43',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64516,num:16,uid:4111,content:'https://github.com/tywo45/t-io 要不看看 tio 不过好像这个框架用的人不多 评价不高',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 10:59:15',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64517,num:17,uid:629,content:'#9 JDK24 修了 synchronized 问题',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 11:01:54',updatedAt:'2025-03-21 12:06:57',mentionNum:9,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64518,num:18,uid:642,content:'那 JDK21 的人不就是小白鼠了!',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 11:05:15',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:64519,num:19,uid:642,content:'升级 JDK 不是说我想升就能升,企业用 J**a 要的是稳定!',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 11:05:51',updatedAt:'2025-03-21 12:06:57',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[6157,{uid:6157,url:'/u/0f1e7d266a045c71616f516f31510715',avatar:'/a/0f1e7d266a045c71616f516f31510715',username:'anyele🤖',}],[1330,{uid:1330,url:'/u/2c1364186a045c766369566f14073c12',avatar:'/a/2c1364186a045c766369566f14073c12',username:'ZeroDu🤖',}],[629,{uid:629,url:'/u/6e22430e6a045c7766685f6f1a2d662f',avatar:'/a/6e22430e6a045c7766685f6f1a2d662f',username:'ychost🤖',}],[58,{uid:58,url:'/u/6c314b256a045c77606f5e6f032a181e',avatar:'/a/6c314b256a045c77606f5e6f032a181e',username:'sagaxu🤖',}],[642,{uid:642,url:'/u/6f26512f6a045c77666e546f3e3c6a71',avatar:'/a/6f26512f6a045c77666e546f3e3c6a71',username:'5261🤖',}],[3082,{uid:3082,url:'/u/120f7d1c6a045c746062546f190c1931',avatar:'/a/120f7d1c6a045c746062546f190c1931',username:'me1onsoda🤖',}],[4111,{uid:4111,url:'/u/69707e146a045c73616b576f111f1a00',avatar:'/a/69707e146a045c73616b576f111f1a00',username:'halov🤖',}],[279,{uid:279,url:'/u/0b1b415b6a045c77626d5f6f2d186b29',avatar:'/a/0b1b415b6a045c77626d5f6f2d186b29',username:'Karte🤖',}],[3778,{uid:3778,url:'/u/360b0b386a045c74676d5e6f223c3c72',avatar:'/a/360b0b386a045c74676d5e6f223c3c72',username:'Goooooos🤖',}],[11395,{uid:11395,url:'/u/0226545a6a045d766363536f122f1f04',avatar:'/a/0226545a6a045d766363536f122f1f04',username:'ZZ74🤖',}],[5791,{uid:5791,url:'/u/15106b5b6a045c726763576f01131c0a',avatar:'/a/15106b5b6a045c726763576f01131c0a',username:'cheng6563🤖',}],[874,{uid:874,url:'/u/6e0864216a045c77686d526f2e030611',avatar:'/a/6e0864216a045c77686d526f2e030611',username:'wxw752🤖',}],]),related:[{title:'有在 vscode 上写 Java 的么?一个非常简单的扩展:可以一键复制 arthas 的 watch 命令。',url:'/d/0b26510b6a045c77606a567a455e606a5f011624',},{title:'「郑州」招聘高级 Java 15K 上下,看个人水平',url:'/d/6a2d46346a045c77606a56754e58616a0e216467',},{title:'技术栈选择: Java 还是 Python',url:'/d/2878683b6a045c77606a5675475d616a083a1603',},{title:'Java 开发,接下来的路咋走啊?',url:'/d/1f78462e6a045c77606a5675475b656a1c37230a',},{title:'windsurf 和 cursor 用来写 kotlin 后端还是不太行',url:'/d/2b780b5e6a045c77606a5674425a656a2d103a64',},{title:'Java 后端开发 , macbookAir m4 16+256G 入门款值得入手不,pdd6199 元,(之前那个 MacBookpro 2018 32G+512G 电脑坏了修起来要 4k 以上,没什么维修价值了)另外问一下够用不',url:'/d/200d00356a045c77606a5674435b6b6a0d276310',},{title:'C++ 开发不想 996,如何跳槽转到 Java ?',url:'/d/09207c086a045c77606a56744358646a1f292613',},{title:'Java 和 go 都会,以后找工作偏向哪个方面好呢',url:'/d/000b7b1b6a045c77606a5674445e656a1977262a',},{title:'作为一个传统开发者,如何使用 ai 或者机器学习实现一些简单事情',url:'/d/34015f186a045c77606a5674445e626a25016611',},{title:'为什么很多人喷 Java 开发者离了 spring 框架就不会写代码了',url:'/d/2c795a5c6a045c77606a56764051666a58303c13',},{title:'Java 找工作有感,行业经验大于一切',url:'/d/3d06072a6a045c77606a5676405c616a050b2611',},{title:'小白发问,都说 C++开发效率比 Java 低,但 C++的 hello world 也没多几行代码啊',url:'/d/6f7157036a045c77606a5676425b616a342a1235',},{title:'作为 Java 狗的我,学习 rust 的时候为啥总念着 go 的好呢?',url:'/d/6f2a02176a045c77606a5671435d636a2f121465',},{title:'原 Java 刚学习 go, 自己在写项目, 针对 go 日志方面的疑惑',url:'/d/6b2c02596a045c77606a56714359626a0f361626',},{title:'Java ReentrantLock 冗余设计?',url:'/d/301a573d6a045c77606a56734759666a5c170733',},{title:'主力开发工具不是 VS 的比如 Java ,如何使用大模型辅助开发呢?转到 VS 或者 IDEA 有什么可以使用大模型 API 的插件?',url:'/d/332c065d6a045c77606a56734759676a2a021e61',},],} const App={setup(){const goTo=useGoTo() const{mdAndUp}=useDisplay() return{goTo,mdAndUp}},data(){return data;},mounted(){const themeDark=localStorage.getItem("themeDark") if(themeDark!==null){this.theme.dark=JSON.parse(themeDark)} if(this.nav.post.total>(this.nav.post.currentPage-1)*100+20){let moreLen=100 if(this.nav.post.total({id:null,num:(this.nav.post.currentPage-1)*100+v,uid:null,content:null,ipRegion:null,updatedByUid:null,createdAt:null,updatedAt:null,mentionNum:null,mentionedBy:null,mentionUsers:null,likeUsers:null,})) this.posts.push(...morePosts.slice(20))} this.workerStart() const hash=window.location.hash const match=hash.match(/#(\d+)/) if(match){const n=parseInt(match[1],10) if(n>=(this.nav.post.currentPage-1)*100&&n{this.jumpTo(n)})}} this.$nextTick(()=>{this.addHeadingIds() tocbot.init({tocSelector:'.toc',contentSelector:'#post-content-0',headingSelector:'h2, h3, h4',headingsOffset:100,scrollSmoothOffset:-100,scrollSmooth:true,collapseDepth:6,onClick:function(e){setTimeout(()=>{history.replaceState(null,'',window.location.pathname+window.location.search)},0)},}) tocbot.refresh()});},beforeUnmount(){this.workerStop() if(this.quill){this.quill.destroy() this.quill=null}},computed:{dposts(){return this.posts.slice(20);},},created(){},methods:{successAlert(msg){this.alert={show:true,color:'success',text:msg,timeout:1500,}},failureAlert(msg){this.alert={show:true,color:'error',text:msg,timeout:5000,}},flipThemeDark(){this.theme.dark=!this.theme.dark localStorage.setItem("themeDark",JSON.stringify(this.theme.dark))},toSearch(){if(!this.search.text){this.failureAlert('搜索词不能为空') return} let keywords=this.search.text.trim() if(keywords.length<1){this.failureAlert('搜索词不能为空') return} if(keywords.length>100){this.failureAlert('搜索词过长') return} this.doSearch(keywords)},toReg(){window.location.href="/reg"},toLogin(){window.location.href="/login"},toPage(){let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,this.nav.post.targetPage>1?`/${this.nav.post.targetPage}`:'') window.location.href=url},toLoadRelated({done}){if(this.my&&this.my.uid){this.apiLoadRelated({done})}else{done('ok')}},workerStart(){this.nav.post.worker=setInterval(()=>{this.workerLoad()},500);},workerStop(){if(this.nav.post.worker){clearInterval(this.nav.post.worker);this.nav.post.worker=null;}},async jumpTo(num){const page=Math.floor(num/100)+1 const i=num-(page-1)*100 if(page===this.nav.post.currentPage){this.goTo("#post-"+num,this.nav.post.goToOptions) if(!this.posts[i].id){const block=Math.floor(num/20)+1 this.nav.post.apiLock[block]=true await this.apiLoadPosts(block) this.$nextTick(()=>{this.goTo("#post-"+num,this.nav.post.goToOptions)})}}else{let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,page>1?`/${page}`:'') url=url+"#"+num window.location.href=url}},postIntersect(num){return(isIntersecting,entries,observer)=>{if(isIntersecting){this.nav.post.task.push(num) this.nav.post.active.push(num) this.nav.post.active=this.nav.post.active.filter(item=>Math.abs(item-num)<=5) this.nav.post.active.sort((a,b)=>a-b)}else{this.nav.post.active=this.nav.post.active.filter(item=>item!==num)} if(this.nav.post.active[0]){this.nav.post.anchor=this.nav.post.active[0]}else{this.nav.post.anchor=0}}},async apiLoadPosts(block){try{const response=await axios.post('/fapi/v1/post/block/'+block,{discussionId:this.nav.post.discussionId,}) if(response.data.code===0){response.data.data.posts.forEach(post=>{const i=post.num%100 Object.assign(this.posts[i],post)}) response.data.data.users.forEach(user=>{this.usersMap.set(user.uid,user)})}else{this.failureAlert('回帖数据加载失败: '+response.data.msg)}}catch(error){this.failureAlert('回帖数据加载失败: '+error)} this.nav.post.apiLock[block]=false},workerLoad(){while(this.nav.post.task.length){const num=this.nav.post.task.pop() const i=num-(this.nav.post.currentPage-1)*100 if(!this.posts[i].id){const block=Math.floor(num/20)+1 if(!this.nav.post.apiLock[block]){this.nav.post.apiLock[block]=true this.apiLoadPosts(block)}}}},getTimeInfo(t){if(!t){return ""} const now=new Date();const then=new Date(t);const diff=now-then;const minute=60*1000;const hour=minute*60;const day=hour*24;const month=day*30;const year=month*12;if(diffpost.num===num) if(!post){return "#"+num} const uid=post.uid const username=this.usersMap.get(uid)?.username if(!username){return "#"+num} return username},getUsernameByPostId(id){const post=this.posts.find(post=>post.id===id) if(!post){return "#"+this.getPostNumByPostId(id)} const uid=post.uid const username=this.usersMap.get(uid).username if(!username){return "#"+this.getPostNumByPostId(id)} return username},getPostNumByPostId(id){const post=this.posts.find(post=>post.id===id) return post.num},getPostById(id){const post=this.posts.find(post=>post.id===id) return post},getPostByNum(num){const post=this.posts.find(post=>post.num===num) return post},getAvatarByUid(uid){const avatar=this.usersMap.get(uid)?.avatar if(!avatar){return this.getRandomAvatar()} return avatar},getAvatarByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post){return this.getRandomAvatar()} const uid=post.uid return this.getAvatarByUid(uid)},getRandomAvatar(){const num=Math.floor(Math.random()*100) return "https://randomuser.me/api/portraits/men/"+num+".jpg"},getUrlByUid(uid){const url=this.usersMap.get(uid)?.url if(!url){return ""} return url},getTextByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post||!post.content){return '点击跳转到#'+num+'查看'} const parser=new DOMParser() const doc=parser.parseFromString(post.content,'text/html') const text=doc.body.textContent||'' return text.slice(0,100)},addHeadingIds(){const content=document.getElementById('post-content-0') if(!content){this.nav.showTOC=false return} const headings=content.querySelectorAll('h2, h3, h4') headings.forEach((heading,index)=>{if(!heading.id){heading.id=`toc-nav-${index}`}}) if(headings.length==0){this.nav.showTOC=false}},async doSearch(keywords){this.search.loading=true try{const response=await axios.post('/fapi/v1/search',{keywords:keywords,}) if(response.data.code===0){if(response.data.data.hash&&response.data.data.hash.length===32){window.location.href="/s/"+response.data.data.hash}else{this.failureAlert('搜索失败: 搜索服务异常')}}else{this.failureAlert('搜索失败: '+response.data.msg)}}catch(error){this.failureAlert('搜索失败: '+error)} this.search.loading=false},debounce(fn,delay){let timer=null return function(...args){if(timer)clearTimeout(timer) timer=setTimeout(()=>{fn.apply(this,args)},delay);};},},watch:{'nav.post.targetPage':{handler:async function(newV,oldV){this.toPage()},immediate:false},},} const vuetify=createVuetify({defaults:{global:{ripple:true,},},}) const app=createApp(App) app.use(vuetify).mount("#app")