Posts

How to Override A Method in Java -

i play robocode (it java programming game). want change method public void onscannedrobot (scannedrobotevent e) { } to public int onscannedrobot(scannedrobotevent e){ } so can adapt robot more if scanned true or false. i heard possible overriding method. tryed it: i wrote: public void onscannedrobot(scannedrobotevent e) { public int onscannedrobot(scannedrobotevent e) { return 1; } } but won't work this won't work because return type of overriden method should same or subtype of return type declared in original method. @ link overriding , overloading

android - linearLayout not included in R java file -

so following tutorial found here: developer site . my code looks below : import android.os.bundle; import android.app.activity; import android.widget.linearlayout; import com.google.android.gms.ads.adrequest; import com.google.android.gms.ads.adsize; import com.google.android.gms.ads.adview; // simple {@link activity} embeds adview. public class mainactivity extends activity { // view show ad. private adview adview; // ad unit id. replace actual ad unit id. private static final string ad_unit_id = "insert_your_ad_unit_id_here"; // called when activity first created. @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // create ad. adview = new adview(this); adview.setadsize(adsize.banner); adview.setadunitid(ad_unit_id); // add adview view hierarchy. view have no size // until ad loaded. linearlayout layout = (linearlayout) findvi...

c++ - Doing a section with one thread and a for-loop with multiple threads -

i using openmp , want spawn threads such 1 thread executes 1 piece of code , finishes, in parallel n threads running iterations of parallel-for loop. execution should this: section (one thread) || section b (parallel-for, multiple threads) | || | | | | | | | | | | | || | | | | | | | | | | | || | | | | | | | | | | | || | | | | | | | | | | | || | | | | | | | | | | v || v v v v v v v v v v i cannot write parallel-for #pragma omp once because not want thread executes section execute for-loop. i have tried this: #pragma omp parallel sections { #pragma omp section { // section } #pragma omp section { // section b; #pragma omp parallel (int = 0; < x; ++i) something(); } } however, parallel...

function - Meteor - Setting Session variables in Asynchronous Calls -

i have problem setting session variables inside of meteor.call function. appears meteor won't set session variables whatever ask outside of scope of function. meteor.startup(function () { // code run on server @ startup // prompt name var playername = prompt("please enter name:", ""); meteor.call('createplayer', playername, function(error, result) { console.log("player_id: " + result); session.set("myplayerid", result); console.log("session_player_id: " + session.get("myplayerid")); }); console.log("session_player_id2: " + session.get("myplayerid")); session.set("gamestate", show_lobby); }); the console prints out: player_id: correct id session_player_id: correct id session_player_id2: undefined as can see, session variable no longer correct outside of scope of function. suggestions? the call createplayer asynchronous, order of exec...

nginx - Show in php how many 502 errors the server has -

i want show using php how many 502 errors server(nginx) have in last 24 hours. couldn't find simple way thanks! there no single way this. better solution, proxy server accepting requests local ip address. work (not tested) the simple solution: grep '502' access.log | wc -l the complex solution: http { upstream error_logger { server 127.0.0.1:80 } } server { error_page 502 /502.html location / { # config here } location /502.html { internal; proxy_pass http://error_logger/502.php; } } the script (502.php); <?php if($_server['remote_addr'] != '127.0.0.1') die(); // logging here

multithreading - Java When using synchronized do I get volatile functionality for free? -

i read several posts concurrency problems i'm still unsure something. can when using synchronized, volatile functionality free, because when lock on object released, next thread reads modified object. volatile, value of object reflected other threads. when use synchronized, there no possibility reflect due lock on object. when lock released, thread may access it. don't have care reflecting value other threads. understand right? [update] example prints 1 2 3 4 5 6 7 8 9 without volatile. package main; public class counter { public static long count = 0; } public class usecounter implements runnable { public void increment() { synchronized (this) { counter.count++; system.out.print(counter.count + " "); } } @override public void run() { increment(); increment(); increment(); } } public class datarace { public static void main(string args[]) ...

c# - Event aggregator and BLL -

i've got winform app 3 layer architecture ui bll (business logic/layer) dal (data access layer) the dal contains factory instantiate proxies used communicate various apis, require credentials of private methods when app starts, 1 or more proxies initialised singletons (1 per api). references singleton kept within app @ ui , bll levels (and maybedal later). the user can choose @ time modify api credentials via ui. in case, want initialise new instances of the singletons, , make sure correct instances used everywhere (ui, bll, dal) what did far is: notify factory of credentials changes, singletons reinitialised used event aggregator pattern in ui, components holding references singleton notified of credential changes , call proxy factory fresh instance however, wanted use event aggregator pattern in ui. question is: how notify objects in bll/dal of change? a solution never hold instances , call factory, there way of doing want properly? edit : have class...